Make WordPress Core

Changeset 39274


Ignore:
Timestamp:
11/17/2016 03:02:40 AM (8 years ago)
Author:
boonebgorges
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-comment-query.php

    r38849 r39274  
    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 );
  • trunk/tests/phpunit/tests/comment/query.php

    r38446 r39274  
    25452545
    25462546    /**
     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
     2580    /**
    25472581     * @ticket 27571
    25482582     */
Note: See TracChangeset for help on using the changeset viewer.