wp_defer_comment_counting example



    if ( $do_deferred ) {
        $_deferred = array_unique( $_deferred );
        foreach ( $_deferred as $i => $_post_id ) {
            wp_update_comment_count_now( $_post_id );
            unset( $_deferred[ $i ] );
            /** @todo Move this outside of the foreach and reset $_deferred to an array instead */
        }
    }

    if ( wp_defer_comment_counting() ) {
        $_deferred[] = $post_id;
        return true;
    } elseif ( $post_id ) {
        return wp_update_comment_count_now( $post_id );
    }

}

/** * Updates the comment count for the post. * * @since 2.5.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $post_id Post ID * @return bool True on success, false if the post does not exist. */
// Do raw query. wp_get_post_revisions() is filtered.     $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
    // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.     foreach ( $revision_ids as $revision_id ) {
        wp_delete_post_revision( $revision_id );
    }

    // Point all attachments to this post up one level.     $wpdb->update( $wpdb->posts, $parent_data$parent_where + array( 'post_type' => 'attachment' ) );

    wp_defer_comment_counting( true );

    $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $postid ) );
    foreach ( $comment_ids as $comment_id ) {
        wp_delete_comment( $comment_id, true );
    }

    wp_defer_comment_counting( false );

    $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ) );
    foreach ( $post_meta_ids as $mid ) {
        delete_metadata_by_mid( 'post', $mid );
    }
'deleted',
            'spammed',
            'unspammed',
            'approved',
            'unapproved',
            'ids',
        ),
        wp_get_referer()
    );
    $redirect_to = add_query_arg( 'paged', $pagenum$redirect_to );

    wp_defer_comment_counting( true );

    foreach ( $comment_ids as $comment_id ) { // Check the permissions on each.         if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
            continue;
        }

        switch ( $doaction ) {
            case 'approve':
                wp_set_comment_status( $comment_id, 'approve' );
                $approved++;
                break;
            
Home | Imprint | This part of the site doesn't use cookies.