From ddc75e22eea51d6c90d5821e03ecec19e5a9cb75 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sat, 3 Oct 2015 19:15:55 +0000 Subject: [PATCH] Only count top-level comments when calculating threaded pagination. The change in [34535] did not properly account for threading. See #13939, #11334. git-svn-id: https://develop.svn.wordpress.org/trunk@34805 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment-functions.php | 1 + .../tests/comment/getPageOfComment.php | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/wp-includes/comment-functions.php b/src/wp-includes/comment-functions.php index 9afc3a55a1..ce6c2d0e82 100644 --- a/src/wp-includes/comment-functions.php +++ b/src/wp-includes/comment-functions.php @@ -881,6 +881,7 @@ function get_page_of_comment( $comment_ID, $args = array() ) { 'fields' => 'ids', 'count' => true, 'status' => 'approve', + 'parent' => 0, 'date_query' => array( array( 'column' => "$wpdb->comments.comment_date_gmt", diff --git a/tests/phpunit/tests/comment/getPageOfComment.php b/tests/phpunit/tests/comment/getPageOfComment.php index 78e53d5d44..b61a6a62af 100644 --- a/tests/phpunit/tests/comment/getPageOfComment.php +++ b/tests/phpunit/tests/comment/getPageOfComment.php @@ -191,4 +191,39 @@ class Tests_Comment_GetPageOfComment extends WP_UnitTestCase { $found_1 = get_page_of_comment( $comments_1[1], array( 'per_page' => 2 ) ); $this->assertEquals( 2, $found_1 ); } + + /** + * @ticket 13939 + */ + public function test_only_top_level_comments_should_be_included_in_older_count() { + $post = $this->factory->post->create(); + + $now = time(); + $comment_parents = $comment_children = array(); + for ( $i = 0; $i < 5; $i++ ) { + $parent = $this->factory->comment->create( array( 'comment_post_ID' => $post, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ) ) ); + $comment_parents[ $i ] = $parent; + + $child = $this->factory->comment->create( array( 'comment_post_ID' => $post, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 59 ) ), 'comment_parent' => $parent ) ); + $comment_children[ $i ] = $child; + } + + $page_1_indicies = array( 2, 3, 4 ); + $page_2_indicies = array( 0, 1 ); + + $args = array( + 'per_page' => 3, + 'max_depth' => 2, + ); + + foreach ( $page_1_indicies as $p1i ) { + $this->assertSame( 1, (int) get_page_of_comment( $comment_parents[ $p1i ], $args ) ); + $this->assertSame( 1, (int) get_page_of_comment( $comment_children[ $p1i ], $args ) ); + } + + foreach ( $page_2_indicies as $p2i ) { + $this->assertSame( 2, (int) get_page_of_comment( $comment_parents[ $p2i ], $args ) ); + $this->assertSame( 2, (int) get_page_of_comment( $comment_children[ $p2i ], $args ) ); + } + } }