Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
31 changes: 31 additions & 0 deletions tests/phpunit/tests/comment/getLastCommentModified.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading