AnsPress_Admin_Ajax::recount_votes()
Description #
Ajax callback for ‘ap_recount_votes` which recounting votes of posts.
Source #
File: admin/ajax.php
public static function recount_votes() {
if ( ! anspress_verify_nonce( 'recount_votes' ) || ! current_user_can( 'manage_options' ) ) {
wp_die();
}
$paged = (int) ap_sanitize_unslash( 'paged', 'r', 0 );
$offset = absint( $paged * 100 );
global $wpdb;
$ids = $wpdb->get_col( "SELECT SQL_CALC_FOUND_ROWS ID FROM {$wpdb->posts} WHERE post_type IN ('question', 'answer') LIMIT {$offset},100" ); // phpcs:ignore WordPress.DB
$total_found = $wpdb->get_var( 'SELECT FOUND_ROWS()' ); // phpcs:ignore WordPress.DB
foreach ( (array) $ids as $id ) {
ap_update_votes_count( $id );
}
$done = $offset + count( $ids );
$remain = $total_found - ( $offset + count( $ids ) );
$json = array(
'success' => true,
'total' => $total_found,
'remain' => $remain,
'el' => '.ap-recount-votes',
// translators: %1 is total completed, %2 is total found count.
'msg' => sprintf( __( '%1$d done out of %2$d', 'anspress-question-answer' ), $done, $total_found ),
);
if ( $remain > 0 ) {
$json['q'] = array(
'action' => 'ap_recount_votes',
'__nonce' => wp_create_nonce( 'recount_votes' ),
'paged' => $paged + 1,
);
}
ap_send_json( $json );
}
Expand full source code Collapse full source code View on GitHub: admin/ajax.php:301
Add your comment