WordPress.org

Make WordPress Core

Changeset 38740


Ignore:
Timestamp:
10/06/2016 05:41:51 PM (20 months ago)
Author:
rachelbaker
Message:

Comments: Account for the comment_order option in get_page_of_comment().

Use the value of the comment_order setting to determine the date_query key to pass to WP_Comment_Query.
Fixes a bug where sites that had comments ordered "newest" first would have the incorrect page number returned.

Props tyxla, boonebgorges.
Fixes #31101.

Location:
trunk
Files:
2 edited

Legend:

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

    r38738 r38740  
    919919            return get_page_of_comment( $comment->comment_parent, $args );
    920920
     921        if ( 'desc' === get_option( 'comment_order' ) ) {
     922            $compare = 'after';
     923        } else {
     924            $compare = 'before';
     925        }
     926
    921927        $comment_args = array(
    922928            'type'       => $args['type'],
     
    929935                array(
    930936                    'column' => "$wpdb->comments.comment_date_gmt",
    931                     'before' => $comment->comment_date_gmt,
     937                    $compare => $comment->comment_date_gmt,
    932938                )
    933939            ),
  • trunk/tests/phpunit/tests/comment/getPageOfComment.php

    r35331 r38740  
    239239        $this->assertEquals( 2, get_page_of_comment( $c1 ) );
    240240    }
     241
     242    /**
     243     * @ticket 31101
     244     */
     245    public function test_should_respect_comment_order_newest() {
     246        $now = time();
     247
     248        $p = self::factory()->post->create();
     249        $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) );
     250        $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) );
     251        $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) );
     252
     253        update_option( 'comment_order', 'desc' );
     254        update_option( 'page_comments', 1 );
     255        update_option( 'comments_per_page', 2 );
     256
     257        $this->assertEquals( 2, get_page_of_comment( $c3 ) );
     258    }
    241259}
Note: See TracChangeset for help on using the changeset viewer.