WordPress.org

Make WordPress Core

Changeset 36158


Ignore:
Timestamp:
01/03/2016 02:06:04 AM (4 years ago)
Author:
boonebgorges
Message:

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.

Location:
branches/4.4
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/4.4

  • branches/4.4/src/wp-includes/comment-template.php

    r36041 r36158  
    19251925     */
    19261926    $r = apply_filters( 'wp_list_comments_args', $r );
     1927
     1928    /*
     1929     * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
     1930     * perform a separate comment query and allow Walker_Comment to paginate.
     1931     */
     1932    if ( is_singular() && ( $r['page'] || $r['per_page'] ) ) {
     1933        $current_cpage = get_query_var( 'cpage' );
     1934        if ( ! $current_cpage ) {
     1935            $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
     1936        }
     1937
     1938        $current_per_page = get_query_var( 'comments_per_page' );
     1939        if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {
     1940            $comments = get_comments( array(
     1941                'post_id' => get_queried_object_id(),
     1942                'orderby' => 'comment_date_gmt',
     1943                'order' => 'ASC',
     1944                'status' => 'all',
     1945            ) );
     1946        }
     1947    }
    19271948
    19281949    // Figure out what comments we'll be looping through ($_comments)
Note: See TracChangeset for help on using the changeset viewer.