Last active
January 10, 2024 08:25
-
-
Save doiftrue/967b7a626da883880f553bfe75d0ed97 to your computer and use it in GitHub Desktop.
https://wp-kama.ru/16747. Дополнение к плагину KCC: в шаблоне выводиться ссылка из метаполя 'comp_ref', количество кликов по ней дублируются в метаполе записи 'comp_ref_clicks'.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
## Добавлет/обновляет количество кликов по ссылке из метаполя 'comp_ref' в метаполе 'comp_ref_clicks' | |
//do_action('kcc_count_after', $args, $updated, $data ); | |
add_action( 'kcc_count_after', 'write_postmeta_link_clicks' ); | |
function write_postmeta_link_clicks( $args ){ | |
$post_id = (int) $args['in_post']; | |
if( | |
// пост не указан - не наш случай | |
! $post_id | |
// проверим, что это нужный пост | |
|| get_post_meta( $post_id, 'comp_ref', true ) !== $args['link_url'] | |
){ | |
return; | |
} | |
// получим новые данные кликов | |
$clicks_data = KCC::$inst->get_link( $args['kcc_url'] ); | |
if( ! $clicks_data ){ | |
return; | |
} | |
update_post_meta( $post_id, 'comp_ref_clicks', $clicks_data->link_clicks ); | |
} | |
add_filter( 'the_content', function( $txt ){ | |
global $post; | |
return $txt . '<a href="'. get_post_meta( $post->ID, 'comp_ref', true ) .'" class="count" data-kccpid="'. $post->ID .'">ссылка KCC</a>'; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment