diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php
index b677851..f419b86 100644
|
|
function wp_list_comments( $args = array(), $comments = null ) { |
1925 | 1925 | */ |
1926 | 1926 | $r = apply_filters( 'wp_list_comments_args', $r ); |
1927 | 1927 | |
| 1928 | // If a 'page' has been passed that does not match what's in $wp_query, perform a separate query. |
| 1929 | if ( ( is_single() || is_page() ) && $r['page'] ) { |
| 1930 | $current_cpage = get_query_var( 'cpage' ); |
| 1931 | $default_comments_page = get_option( 'default_comments_page' ); |
| 1932 | if ( ! $current_cpage ) { |
| 1933 | $current_cpage = 'newest' === $default_comments_page ? 1 : $wp_query->max_num_comment_pages; |
| 1934 | } |
| 1935 | |
| 1936 | if ( $r['page'] != $current_cpage ) { |
| 1937 | $comments = get_comments( array( |
| 1938 | 'post_id' => get_queried_object_id(), |
| 1939 | 'orderby' => 'comment_date_gmt', |
| 1940 | 'order' => 'newest' === $default_comments_page ? 'ASC' : 'DESC', |
| 1941 | 'status' => 'all', |
| 1942 | ) ); |
| 1943 | } |
| 1944 | } |
| 1945 | |
1928 | 1946 | // Figure out what comments we'll be looping through ($_comments) |
1929 | 1947 | if ( null !== $comments ) { |
1930 | 1948 | $comments = (array) $comments; |
diff --git tests/phpunit/tests/wpListComments.php tests/phpunit/tests/wpListComments.php
new file mode 100644
index 0000000..5e35604
-
|
+
|
|
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @group comment |
| 5 | */ |
| 6 | class Tests_Comment_WpListComments extends WP_UnitTestCase { |
| 7 | /** |
| 8 | * @ticket 35175 |
| 9 | */ |
| 10 | public function test_should_respect_page_param() { |
| 11 | $p = self::factory()->post->create(); |
| 12 | |
| 13 | $comments = array(); |
| 14 | $now = time(); |
| 15 | for ( $i = 0; $i <= 5; $i++ ) { |
| 16 | $comments[] = self::factory()->comment->create( array( |
| 17 | 'comment_post_ID' => $p, |
| 18 | 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ), |
| 19 | 'comment_author' => 'Commenter ' . $i, |
| 20 | ) ); |
| 21 | } |
| 22 | |
| 23 | update_option( 'page_comments', true ); |
| 24 | update_option( 'comments_per_page', 2 ); |
| 25 | |
| 26 | $this->go_to( get_permalink( $p ) ); |
| 27 | |
| 28 | // comments_template() populates $wp_query->comments |
| 29 | get_echo( 'comments_template' ); |
| 30 | |
| 31 | $found = wp_list_comments( array( |
| 32 | 'page' => 2, |
| 33 | 'echo' => false, |
| 34 | ) ); |
| 35 | |
| 36 | preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches ); |
| 37 | |
| 38 | $this->assertEqualSets( array( $comments[2], $comments[3] ), $matches[1] ); |
| 39 | } |
| 40 | } |