WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/20/2016 05:23:02 AM (5 years ago)
Author:
dd32
Message:

Comments: Always respect $comments array passed to wp_list_comments().

[36157] fixed a bug whereby wp_list_comments() would not properly recognize
custom pagination arguments. See #35175. However, it inadvertently introduced
a bug that caused any $comments array explicitly passed to the function to be
ignored, when that array was accompanied by pagination arguments that differ
from those in $wp_query. We address this bug by moving the logic introduced
in [36157] inside a block that only fires when no $comments array has been
provided to the function.

Merges [36276] to the 4.4 branch.
Props ivankristianto, boonebgorges.
Fixes #35356.

Location:
branches/4.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

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

    r36353 r36356  
    19351935    $r = apply_filters( 'wp_list_comments_args', $r );
    19361936
    1937     /*
    1938      * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
    1939      * perform a separate comment query and allow Walker_Comment to paginate.
    1940      */
    1941     if ( is_singular() && ( $r['page'] || $r['per_page'] ) ) {
    1942         $current_cpage = get_query_var( 'cpage' );
    1943         if ( ! $current_cpage ) {
    1944             $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
    1945         }
    1946 
    1947         $current_per_page = get_query_var( 'comments_per_page' );
    1948         if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {
    1949             $comments = get_comments( array(
    1950                 'post_id' => get_queried_object_id(),
    1951                 'orderby' => 'comment_date_gmt',
    1952                 'order' => 'ASC',
    1953                 'status' => 'all',
    1954             ) );
    1955         }
    1956     }
    1957 
    19581937    // Figure out what comments we'll be looping through ($_comments)
    19591938    if ( null !== $comments ) {
     
    19701949        }
    19711950    } else {
    1972         if ( empty($wp_query->comments) )
    1973             return;
    1974         if ( 'all' != $r['type'] ) {
    1975             if ( empty($wp_query->comments_by_type) )
    1976                 $wp_query->comments_by_type = separate_comments($wp_query->comments);
    1977             if ( empty($wp_query->comments_by_type[$r['type']]) )
     1951        /*
     1952         * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
     1953         * perform a separate comment query and allow Walker_Comment to paginate.
     1954         */
     1955        if ( is_singular() && ( $r['page'] || $r['per_page'] ) ) {
     1956            $current_cpage = get_query_var( 'cpage' );
     1957            if ( ! $current_cpage ) {
     1958                $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
     1959            }
     1960
     1961            $current_per_page = get_query_var( 'comments_per_page' );
     1962            if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {
     1963                $comments = get_comments( array(
     1964                    'post_id' => get_queried_object_id(),
     1965                    'orderby' => 'comment_date_gmt',
     1966                    'order' => 'ASC',
     1967                    'status' => 'all',
     1968                ) );
     1969
     1970                if ( 'all' != $r['type'] ) {
     1971                    $comments_by_type = separate_comments( $comments );
     1972                    if ( empty( $comments_by_type[ $r['type'] ] ) ) {
     1973                        return;
     1974                    }
     1975
     1976                    $_comments = $comments_by_type[ $r['type'] ];
     1977                } else {
     1978                    $_comments = $comments;
     1979                }
     1980            }
     1981
     1982        // Otherwise, fall back on the comments from `$wp_query->comments`.
     1983        } else {
     1984            if ( empty($wp_query->comments) )
    19781985                return;
    1979             $_comments = $wp_query->comments_by_type[$r['type']];
    1980         } else {
    1981             $_comments = $wp_query->comments;
    1982         }
    1983 
    1984         // Pagination is already handled by `WP_Comment_Query`, so we tell Walker not to bother.
    1985         if ( $wp_query->max_num_comment_pages ) {
    1986             $default_comments_page = get_option( 'default_comments_page' );
    1987             $cpage = get_query_var( 'cpage' );
    1988             if ( 'newest' === $default_comments_page ) {
    1989                 $r['cpage'] = $cpage;
    1990 
    1991             // When first page shows oldest comments, post permalink is the same as the comment permalink.
    1992             } elseif ( $cpage == 1 ) {
    1993                 $r['cpage'] = '';
     1986            if ( 'all' != $r['type'] ) {
     1987                if ( empty($wp_query->comments_by_type) )
     1988                    $wp_query->comments_by_type = separate_comments($wp_query->comments);
     1989                if ( empty($wp_query->comments_by_type[$r['type']]) )
     1990                    return;
     1991                $_comments = $wp_query->comments_by_type[$r['type']];
    19941992            } else {
    1995                 $r['cpage'] = $cpage;
     1993                $_comments = $wp_query->comments;
    19961994            }
    19971995
    1998             $r['page'] = 0;
    1999             $r['per_page'] = 0;
     1996            if ( $wp_query->max_num_comment_pages ) {
     1997                $default_comments_page = get_option( 'default_comments_page' );
     1998                $cpage = get_query_var( 'cpage' );
     1999                if ( 'newest' === $default_comments_page ) {
     2000                    $r['cpage'] = $cpage;
     2001
     2002                /*
     2003                 * When first page shows oldest comments, post permalink is the same as
     2004                 * the comment permalink.
     2005                 */
     2006                } elseif ( $cpage == 1 ) {
     2007                    $r['cpage'] = '';
     2008                } else {
     2009                    $r['cpage'] = $cpage;
     2010                }
     2011
     2012                $r['page'] = 0;
     2013                $r['per_page'] = 0;
     2014            }
    20002015        }
    20012016    }
Note: See TracChangeset for help on using the changeset viewer.