diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 20303dc1e7e17..e421f5415dce3 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -363,15 +363,15 @@ function get_lastcommentmodified( $timezone = 'server' ) { switch ( $timezone ) { case 'gmt': - $comment_modified_date = $wpdb->get_var( "SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" ); + $comment_modified_date = $wpdb->get_var( "SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type != 'note' ORDER BY comment_date_gmt DESC LIMIT 1" ); break; case 'blog': - $comment_modified_date = $wpdb->get_var( "SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" ); + $comment_modified_date = $wpdb->get_var( "SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type != 'note' ORDER BY comment_date_gmt DESC LIMIT 1" ); break; case 'server': $add_seconds_server = gmdate( 'Z' ); - $comment_modified_date = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server ) ); + $comment_modified_date = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type != 'note' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server ) ); break; } diff --git a/tests/phpunit/tests/comment/getLastCommentModified.php b/tests/phpunit/tests/comment/getLastCommentModified.php index 03229ba350a9b..9f8f9e08857fb 100644 --- a/tests/phpunit/tests/comment/getLastCommentModified.php +++ b/tests/phpunit/tests/comment/getLastCommentModified.php @@ -11,6 +11,37 @@ public function test_no_comments() { $this->assertFalse( get_lastcommentmodified() ); } + /** + * Ensures internal 'note' comments are excluded from the last modified time. + * + * The value feeds the comments feed Last-Modified/ETag headers, so a note -- + * which is never part of the public feed -- must not bump it. + * + * @ticket 65657 + */ + public function test_notes_are_excluded() { + // A regular approved comment. + self::factory()->comment->create( + array( + 'comment_approved' => '1', + 'comment_date' => '2000-01-01 11:00:00', + 'comment_date_gmt' => '2000-01-01 10:00:00', + ) + ); + + // A later internal note, which must be ignored. + self::factory()->comment->create( + array( + 'comment_approved' => '1', + 'comment_type' => 'note', + 'comment_date' => '2000-01-02 11:00:00', + 'comment_date_gmt' => '2000-01-02 10:00:00', + ) + ); + + $this->assertSame( strtotime( '2000-01-01 10:00:00' ), strtotime( get_lastcommentmodified( 'GMT' ) ) ); + } + public function test_default_timezone() { self::factory()->comment->create_and_get( array(