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
17 changes: 9 additions & 8 deletions src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -1100,14 +1100,15 @@ function get_page_of_comment( $comment_id, $args = array() ) {
}

$comment_args = array(
'type' => $args['type'],
'post_id' => $comment->comment_post_ID,
'fields' => 'ids',
'count' => true,
'status' => 'approve',
'orderby' => 'none',
'parent' => 0,
'date_query' => array(
'type' => $args['type'],
'type__not_in' => array( 'note' ),
'post_id' => $comment->comment_post_ID,
'fields' => 'ids',
'count' => true,
'status' => 'approve',
'orderby' => 'none',
'parent' => 0,
'date_query' => array(
array(
'column' => "$wpdb->comments.comment_date_gmt",
'before' => $comment->comment_date_gmt,
Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/tests/comment/getPageOfComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,38 @@ public function test_last_comment() {
$this->assertSame( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 10 ) ) );
}

/**
* Ensures that internal 'note' comments are excluded from the page calculation.
*
* Notes share the comments table but are never displayed in the public comment
* list, so they must not shift the page a regular comment appears on.
*
* @ticket 65642
*
* @covers ::get_page_of_comment
*/
public function test_notes_should_not_affect_page() {
$p = self::factory()->post->create();

self::factory()->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-14 00:00:00' ) );

// An internal note dated between the two regular comments must be ignored.
self::factory()->comment->create(
array(
'comment_post_ID' => $p,
'comment_type' => 'note',
'comment_approved' => '1',
'comment_parent' => 0,
'comment_date' => '2013-09-15 00:00:00',
)
);

$comment_target = self::factory()->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-16 00:00:00' ) );

// Only one regular comment precedes the target, so it is on page 2.
$this->assertSame( 2, get_page_of_comment( $comment_target[0], array( 'per_page' => 1 ) ) );
}

public function test_type_pings() {
$p = self::factory()->post->create();
$now = time();
Expand Down
Loading