diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index ae759c04f5..ba60070fd7 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -1003,12 +1003,6 @@ function get_page_of_comment( $comment_ID, $args = array() ) { if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) return get_page_of_comment( $comment->comment_parent, $args ); - if ( 'desc' === get_option( 'comment_order' ) ) { - $compare = 'after'; - } else { - $compare = 'before'; - } - $comment_args = array( 'type' => $args['type'], 'post_id' => $comment->comment_post_ID, @@ -1019,7 +1013,7 @@ function get_page_of_comment( $comment_ID, $args = array() ) { 'date_query' => array( array( 'column' => "$wpdb->comments.comment_date_gmt", - $compare => $comment->comment_date_gmt, + 'before' => $comment->comment_date_gmt, ) ), ); diff --git a/tests/phpunit/tests/comment/getPageOfComment.php b/tests/phpunit/tests/comment/getPageOfComment.php index e8c0d4ea5c..580d129228 100644 --- a/tests/phpunit/tests/comment/getPageOfComment.php +++ b/tests/phpunit/tests/comment/getPageOfComment.php @@ -241,18 +241,40 @@ class Tests_Comment_GetPageOfComment extends WP_UnitTestCase { /** * @ticket 31101 + * @ticket 39280 */ - public function test_should_respect_comment_order_newest() { + public function test_should_ignore_comment_order() { $now = time(); $p = self::factory()->post->create(); $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) ); $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) ); $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) ); + $c4 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ) ) ); update_option( 'comment_order', 'desc' ); update_option( 'page_comments', 1 ); - update_option( 'comments_per_page', 2 ); + update_option( 'comments_per_page', 1 ); + + $this->assertEquals( 2, get_page_of_comment( $c3 ) ); + } + + /** + * @ticket 31101 + * @ticket 39280 + */ + public function test_should_ignore_default_comment_page() { + $now = time(); + + $p = self::factory()->post->create(); + $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) ); + $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) ); + $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) ); + $c4 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ) ) ); + + update_option( 'default_comment_page', 'newest' ); + update_option( 'page_comments', 1 ); + update_option( 'comments_per_page', 1 ); $this->assertEquals( 2, get_page_of_comment( $c3 ) ); }