Comments: In `wp_list_comments()`, queries with custom pagination params should obey default `comment_status` logic.

When custom pagination parameters are passed to `wp_list_comments()`, a
secondary query must be performed to fetch the proper comments. See [36157].
This query should show comments of the same `comment_status` as the default
query initialized in `comments_template()`: show only comments that are
approved, or those that are unapproved but belong to the current user.

Props smerriman.
Fixes #37048.
Built from https://develop.svn.wordpress.org/trunk@37655


git-svn-id: http://core.svn.wordpress.org/trunk@37621 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2016-06-08 04:01:27 +00:00
parent 7097e7748e
commit 838156a958
2 changed files with 15 additions and 5 deletions

View File

@ -1960,13 +1960,23 @@ function wp_list_comments( $args = array(), $comments = null ) {
$current_per_page = get_query_var( 'comments_per_page' );
if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {
$comments = get_comments( array(
$comment_args = array(
'post_id' => get_the_ID(),
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'all',
) );
'status' => 'approve',
);
if ( is_user_logged_in() ) {
$comment_args['include_unapproved'] = get_current_user_id();
} else {
$commenter = wp_get_current_commenter();
if ( $commenter['comment_author_email'] ) {
$comment_args['include_unapproved'] = $commenter['comment_author_email'];
}
}
$comments = get_comments( $comment_args );
if ( 'all' != $r['type'] ) {
$comments_by_type = separate_comments( $comments );

View File

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