Вот используемые функции:
Код: Выделить всё
function tb_update_old_followers($user_id) {
$followers = tb_get_follower_count($user_id);
$old_followers = tb_get_old_follower_count($user_id);
$response['new_new_followers'] = $followers;
$response['old_new_followers'] = $old_followers;
$response = json_encode( $response );
echo $response;
update_user_meta( $user_id, '_tb_old_followed_by_count', $followers + 1);
die();
}
add_action('wp_ajax_tb_update_old_followers' , 'tb_update_old_followers');
function tb_get_follower_count( $user_id = null ) {
if ( empty( $user_id ) ) {
$user_id = get_current_user_id();
}
$followed_count = get_user_meta( $user_id, '_tb_followed_by_count', true );
$count = 0;
if ( $followed_count ) {
$count = $followed_count;
}
return (int) apply_filters( 'tb_get_follower_count', $count, $user_id );
}
function tb_get_old_follower_count( $user_id = null ) {
if ( empty( $user_id ) ) {
$user_id = get_current_user_id();
}
$old_followed_count = get_user_meta( $user_id, '_tb_old_followed_by_count', true );
$old_count = 0;
if ( $old_followed_count ) {
$old_count = $old_followed_count;
}
return (int) apply_filters( 'tb_get_old_follower_count', $old_count, $user_id );
}
Подробнее здесь: https://stackoverflow.com/questions/510 ... a-via-ajax
Мобильная версия