From 26caa329f2c047f305cb04eb41a890aa8cf080d1 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 21 Dec 2015 03:07:32 +0000 Subject: [PATCH] Respect approval status when determining comment page count in `comments_template()`. Since 4.4, when fetching the first page of comments and the 'newest' comments are set to display first, `comments_template()` must perform arithmetic to determine which comments to show. See #8071. This arithmetic requires the total comment count for the current post, which is calculated with a separate `WP_Comment_Query`. This secondary comment query did not properly account for non-approved comment statuses; all unapproved comments should be part of the comment count for admins, and individual users should have their own unapproved comments included in the count. As a result, `comments_template()` was, in some cases, being fooled into thinking that a post had fewer comments available for pagination than it actually had, which resulted in empty pages of comments. We correct this problem by mirroring 'status' and 'include_unapproved' params of the main comment query within the secondary query used to calculate pagination. Fixes #35068. Built from https://develop.svn.wordpress.org/trunk@36040 git-svn-id: http://core.svn.wordpress.org/trunk@36005 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 11 +++++++++-- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index 84a60dbc4a..f19d1a99da 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -1313,12 +1313,19 @@ function comments_template( $file = '/comments.php', $separate_comments = false } else { // If fetching the first page of 'newest', we need a top-level comment count. $top_level_query = new WP_Comment_Query(); - $top_level_count = $top_level_query->query( array( + $top_level_args = array( 'count' => true, 'orderby' => false, 'post_id' => $post->ID, 'parent' => 0, - ) ); + 'status' => 'approve', + ); + + if ( isset( $comment_args['include_unapproved'] ) ) { + $top_level_args['include_unapproved'] = $comment_args['include_unapproved']; + } + + $top_level_count = $top_level_query->query( $top_level_args ); $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; } diff --git a/wp-includes/version.php b/wp-includes/version.php index fbf4375867..c96a6589d6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36038'; +$wp_version = '4.5-alpha-36040'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.