diff --git src/wp-includes/comment.php src/wp-includes/comment.php
index 58ffb03..9ce11a0 100644
|
|
|
function get_page_of_comment( $comment_ID, $args = array() ) { |
| 913 | 913 | if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) |
| 914 | 914 | return get_page_of_comment( $comment->comment_parent, $args ); |
| 915 | 915 | |
| | 916 | if ( 'desc' === get_option( 'comment_order' ) ) { |
| | 917 | $compare = 'after'; |
| | 918 | } else { |
| | 919 | $compare = 'before'; |
| | 920 | } |
| | 921 | |
| 916 | 922 | $comment_args = array( |
| 917 | 923 | 'type' => $args['type'], |
| 918 | 924 | 'post_id' => $comment->comment_post_ID, |
| … |
… |
function get_page_of_comment( $comment_ID, $args = array() ) { |
| 923 | 929 | 'date_query' => array( |
| 924 | 930 | array( |
| 925 | 931 | 'column' => "$wpdb->comments.comment_date_gmt", |
| 926 | | 'before' => $comment->comment_date_gmt, |
| | 932 | $compare => $comment->comment_date_gmt, |
| 927 | 933 | ) |
| 928 | 934 | ), |
| 929 | 935 | ); |
diff --git tests/phpunit/tests/comment/getPageOfComment.php tests/phpunit/tests/comment/getPageOfComment.php
index b41f649..e8c0d4e 100644
|
|
|
class Tests_Comment_GetPageOfComment extends WP_UnitTestCase { |
| 238 | 238 | |
| 239 | 239 | $this->assertEquals( 2, get_page_of_comment( $c1 ) ); |
| 240 | 240 | } |
| | 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 | } |
| 241 | 259 | } |