mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-31 13:37:51 +01:00
Comments: Add a new pre_wp_update_comment_count_now
filter.
This allows filtering a post's comment count before it is queried and updated in the database. Props peterwilsoncc for initial patch. Fixes #35060. Built from https://develop.svn.wordpress.org/trunk@36318 git-svn-id: http://core.svn.wordpress.org/trunk@36285 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ededb78efc
commit
19d4304565
@ -2094,7 +2094,24 @@ function wp_update_comment_count_now($post_id) {
|
||||
return false;
|
||||
|
||||
$old = (int) $post->comment_count;
|
||||
$new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) );
|
||||
|
||||
/**
|
||||
* Filters a post's comment count before it is updated in the database.
|
||||
*
|
||||
* @since 4.5.0
|
||||
*
|
||||
* @param int $new The new comment count. Default null.
|
||||
* @param int $old The old comment count.
|
||||
* @param int $post_id Post ID.
|
||||
*/
|
||||
$new = apply_filters( 'pre_wp_update_comment_count_now', null, $old, $post_id );
|
||||
|
||||
if ( is_null( $new ) ) {
|
||||
$new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id ) );
|
||||
} else {
|
||||
$new = (int) $new;
|
||||
}
|
||||
|
||||
$wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
|
||||
|
||||
clean_post_cache( $post );
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.5-alpha-1452863892977';
|
||||
$wp_version = '4.5-alpha-1452865332638';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user