Make WordPress Core

Changeset 61336


Ignore:
Timestamp:
12/01/2025 03:31:41 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Notes: Avoid incrementing comment_count when notes are resolved or reopened.

Follow-up to [60987].

Props hbhalodia, wildworks, shimotomoki, gulamdastgir04, JeffPaul, ellatrix, SergeyBiryukov.
Fixes #64325.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r61270 r61336  
    28732873
    28742874        if ( is_null( $new ) ) {
    2875                 $new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id ) );
     2875                $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 ) );
    28762876        } else {
    28772877                $new = (int) $new;
  • trunk/tests/phpunit/tests/comment/wpUpdateCommentCountNow.php

    r56971 r61336  
    4747        }
    4848
     49        /**
     50        * @ticket 64325
     51        */
     52        public function test_only_approved_regular_comments_are_counted() {
     53                $post_id = self::factory()->post->create();
     54
     55                self::factory()->comment->create(
     56                        array(
     57                                'comment_post_ID'  => $post_id,
     58                                'comment_approved' => 0,
     59                        )
     60                );
     61                self::factory()->comment->create(
     62                        array(
     63                                'comment_post_ID'  => $post_id,
     64                                'comment_approved' => 1,
     65                        )
     66                );
     67                self::factory()->comment->create(
     68                        array(
     69                                'comment_post_ID'  => $post_id,
     70                                'comment_type'     => 'note',
     71                                'comment_approved' => 0,
     72                        )
     73                );
     74                self::factory()->comment->create(
     75                        array(
     76                                'comment_post_ID'  => $post_id,
     77                                'comment_type'     => 'note',
     78                                'comment_approved' => 1,
     79                        )
     80                );
     81
     82                $this->assertTrue( wp_update_comment_count_now( $post_id ) );
     83                $this->assertSame( '1', get_comments_number( $post_id ) );
     84        }
     85
    4986        public function _return_100() {
    5087                return 100;
Note: See TracChangeset for help on using the changeset viewer.