Skip to content

Commit 206a330

Browse files
committed
Comments: Query used to fill comment descendants should reset 'offset' and 'number' params.
Descendant queries should not inherit the 'offset' and 'number' parameters of the parent query, or descendants will be missed. Previously: [38497]. See #37696. git-svn-id: https://develop.svn.wordpress.org/trunk@39274 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1e05bf8 commit 206a330

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/wp-includes/class-wp-comment-query.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,8 @@ protected function fill_descendants( $comments ) {
996996
$parent_query_args['parent__in'] = $uncached_parent_ids;
997997
$parent_query_args['no_found_rows'] = true;
998998
$parent_query_args['hierarchical'] = false;
999+
$parent_query_args['offset'] = 0;
1000+
$parent_query_args['number'] = 0;
9991001

10001002
$level_comments = get_comments( $parent_query_args );
10011003

tests/phpunit/tests/comment/query.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,40 @@ public function test_hierarchy_should_be_filled_when_cache_is_incomplete() {
25432543
$this->assertEqualSets( $q1_ids, $q2_ids );
25442544
}
25452545

2546+
/**
2547+
* @ticket 37966
2548+
* @ticket 37696
2549+
*/
2550+
public function test_fill_hierarchy_should_disregard_offset_and_number() {
2551+
$c0 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
2552+
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
2553+
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c1 ) );
2554+
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
2555+
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c3 ) );
2556+
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c3 ) );
2557+
2558+
$q = new WP_Comment_Query();
2559+
$found = $q->query( array(
2560+
'orderby' => 'comment_date_gmt',
2561+
'order' => 'ASC',
2562+
'status' => 'approve',
2563+
'post_id' => self::$post_id,
2564+
'no_found_rows' => false,
2565+
'hierarchical' => 'threaded',
2566+
'number' => 2,
2567+
'offset' => 1,
2568+
) );
2569+
2570+
2571+
$found_1 = $found[ $c1 ];
2572+
$children_1 = $found_1->get_children();
2573+
$this->assertEqualSets( array( $c2 ), array_keys( $children_1 ) );
2574+
2575+
$found_3 = $found[ $c3 ];
2576+
$children_3 = $found_3->get_children();
2577+
$this->assertEqualSets( array( $c4, $c5 ), array_keys( $children_3 ) );
2578+
}
2579+
25462580
/**
25472581
* @ticket 27571
25482582
*/

0 commit comments

Comments
 (0)