Make WordPress Core

Ticket #38268: 38268.2.patch

File 38268.2.patch, 3.0 KB (added by AdamWills, 7 years ago)

Previous upload wasn't what I was expecting. Trying again...

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

    diff --git src/wp-includes/class-wp-comment-query.php src/wp-includes/class-wp-comment-query.php
    index ef8b6d5..67dfcae 100644
    class WP_Comment_Query { 
    183183         *                                                   See WP_Meta_Query. Default empty.
    184184         *     @type int          $number                    Maximum number of comments to retrieve.
    185185         *                                                   Default empty (no limit).
     186         *     @type int          $paged                     When used with number, defines the page of results to return.
     187         *                                                   Default 1.
    186188         *     @type int          $offset                    Number of comments to offset the query. Used to build
    187189         *                                                   LIMIT clause. Default 0.
    188190         *     @type bool         $no_found_rows             Whether to disable the `SQL_CALC_FOUND_ROWS` query.
    class WP_Comment_Query { 
    276278                        'no_found_rows' => true,
    277279                        'orderby' => '',
    278280                        'order' => 'DESC',
     281                        'paged' => '1',
    279282                        'parent' => '',
    280283                        'parent__in' => '',
    281284                        'parent__not_in' => '',
    class WP_Comment_Query { 
    640643
    641644                $number = absint( $this->query_vars['number'] );
    642645                $offset = absint( $this->query_vars['offset'] );
     646                $paged = absint( $this->query_vars['paged'] );
    643647
    644648                if ( ! empty( $number ) ) {
    645649                        if ( $offset ) {
    646650                                $limits = 'LIMIT ' . $offset . ',' . $number;
    647651                        } else {
    648                                 $limits = 'LIMIT ' . $number;
     652                                $limits = 'LIMIT ' . ( $number * ( $paged - 1 ) ) . ',' . $number;
    649653                        }
    650654                }
    651655
  • tests/phpunit/tests/comment/query.php

    diff --git tests/phpunit/tests/comment/query.php tests/phpunit/tests/comment/query.php
    index ff4e3ac..beb8c43 100644
    class Tests_Comment_Query extends WP_UnitTestCase { 
    15611561                $this->assertEquals( 2, $found );
    15621562        }
    15631563
     1564        /**
     1565         * @ticket 38268
     1566         */
     1567        public function test_pagination_query() {
     1568                $comments = self::factory()->comment->create_many( 4, array(
     1569                        'comment_post_ID' => self::$post_id,
     1570                ) );
     1571
     1572                $query1 = new WP_Comment_Query();
     1573                $found1 = $query1->query( array(
     1574                        'paged' => 2,
     1575                        'number' => 2
     1576                ) );
     1577
     1578                $query2 = new WP_Comment_Query();
     1579                $found2 = $query2->query(
     1580                        array(
     1581                                'offset' => 2,
     1582                                'number' => 2
     1583                        )
     1584                );
     1585                $this->assertEqualSets( $found1, $found2 );
     1586        }
     1587
     1588        /**
     1589         * @ticket 38268
     1590         */
     1591        public function test_pagination_offset_conflict() {
     1592                $comments = self::factory()->comment->create_many( 4, array(
     1593                        'comment_post_ID' => self::$post_id,
     1594                ) );
     1595                $query1 = new WP_Comment_Query();
     1596                $found1 = $query1->query( array(
     1597                        'paged' => 2,
     1598                        'offset' => 1,
     1599                        'number' => 2
     1600                ) );
     1601
     1602                $query2 = new WP_Comment_Query();
     1603                $found2 = $query2->query(
     1604                        array(
     1605                                'offset' => 1,
     1606                                'number' => 2
     1607                        )
     1608                );
     1609                $this->assertEqualSets( $found1, $found2 );
     1610        }
     1611
    15641612        public function test_post_type_single_value() {
    15651613                register_post_type( 'post-type-1' );
    15661614                register_post_type( 'post-type-2' );