Ensure that non-default pagination values work in wp_list_comments().

Prior to 4.4, it was possible to pass 'page' and 'per_page' values to
`wp_list_comments()` that do not match the corresponding global query vars.
This ability was lost in 4.4 with the refactor of how `comments_template()`
queries for comments; when the main comment query started fetching only the
comments that ought to appear on a page, instead of all of a post's comments,
it became impossible for the comment walker to select comments corresponding to
custom pagination parameters. See #8071.

We restore the previous behavior by (a) detecting when a 'page' or 'per_page'
parameter has been passed to `wp_list_comments()` that does not match the
corresponding query vars (so that the desired comments will not be found in
`$wp_query`), and if so, then (b) querying for all of the post's comments and
passing them to the comment walker for pagination, as was the case before 4.4.

Merges [36157] to the 4.4 branch.

Props boonebgorges, smerriman.
Fixes #35175.

Built from https://develop.svn.wordpress.org/branches/4.4@36158


git-svn-id: http://core.svn.wordpress.org/branches/4.4@36124 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2016-01-03 02:07:23 +00:00
parent ced6b063a3
commit 15e9e6f6d9
2 changed files with 22 additions and 1 deletions

View File

@ -1925,6 +1925,27 @@ function wp_list_comments( $args = array(), $comments = null ) {
*/
$r = apply_filters( 'wp_list_comments_args', $r );
/*
* If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
* perform a separate comment query and allow Walker_Comment to paginate.
*/
if ( is_singular() && ( $r['page'] || $r['per_page'] ) ) {
$current_cpage = get_query_var( 'cpage' );
if ( ! $current_cpage ) {
$current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
}
$current_per_page = get_query_var( 'comments_per_page' );
if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {
$comments = get_comments( array(
'post_id' => get_queried_object_id(),
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'all',
) );
}
}
// Figure out what comments we'll be looping through ($_comments)
if ( null !== $comments ) {
$comments = (array) $comments;

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4.1-alpha-36155';
$wp_version = '4.4.1-alpha-36158';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.