Make WordPress Core


Ignore:
Timestamp:
10/06/2016 05:41:51 PM (9 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.