Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2872,7 +2872,7 @@ function wp_update_comment_count_now( $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 ) );
$new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND comment_type != 'note'", $post_id ) );
} else {
$new = (int) $new;
}
Expand Down
37 changes: 37 additions & 0 deletions tests/phpunit/tests/comment/wpUpdateCommentCountNow.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,43 @@ public function test_using_filter_adjusts_comment_count_without_an_additional_da
remove_filter( 'pre_wp_update_comment_count_now', array( $this, '_return_100' ) );
}

/**
* @ticket 64325
*/
public function test_only_approved_regular_comments_are_counted() {
$post_id = self::factory()->post->create();

self::factory()->comment->create(
array(
'comment_post_ID' => $post_id,
'comment_approved' => 0,
)
);
self::factory()->comment->create(
array(
'comment_post_ID' => $post_id,
'comment_approved' => 1,
)
);
self::factory()->comment->create(
array(
'comment_post_ID' => $post_id,
'comment_type' => 'note',
'comment_approved' => 0,
)
);
self::factory()->comment->create(
array(
'comment_post_ID' => $post_id,
'comment_type' => 'note',
'comment_approved' => 1,
)
);

$this->assertTrue( wp_update_comment_count_now( $post_id ) );
$this->assertSame( '1', get_comments_number( $post_id ) );
}

public function _return_100() {
return 100;
}
Expand Down
Loading