Comments: Ensure the proper comment count and pages for unapproved comments.

Previiously, unapproved comments can alter the comment count, returning incorrect page numbers.

Fixes #8973.

Props GregMulhauser, dd32, ryan, mrmist, hakre, solarissmoke, billerickson, ericlewis, SergeyBiryukov, chriscct7, dossy, lukecavanagh, renggo888, jdorner, matjack1, pento, audrasjb, imath, davidbaumwald, whyisjake.  



git-svn-id: https://develop.svn.wordpress.org/trunk@48133 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jake Spurlock
2020-06-23 05:22:39 +00:00
parent 888421a924
commit 7b08983ce4
3 changed files with 169 additions and 10 deletions
+5 -10
View File
@@ -1330,6 +1330,7 @@ function wp_comment_form_unfiltered_html_nonce() {
* Will not try to get the comments if the post has none.
*
* @since 1.5.0
* @since 5.5.0 Removed the need to use the $user_ID global.
*
* @global WP_Query $wp_query WordPress Query object.
* @global WP_Post $post Global post object.
@@ -1337,7 +1338,6 @@ function wp_comment_form_unfiltered_html_nonce() {
* @global int $id
* @global WP_Comment $comment Global comment object.
* @global string $user_login
* @global int $user_ID
* @global string $user_identity
* @global bool $overridden_cpage
* @global bool $withcomments
@@ -1347,7 +1347,7 @@ function wp_comment_form_unfiltered_html_nonce() {
* Default false.
*/
function comments_template( $file = '/comments.php', $separate_comments = false ) {
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage;
if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
return;
@@ -1396,14 +1396,9 @@ function comments_template( $file = '/comments.php', $separate_comments = false
$comment_args['hierarchical'] = false;
}
if ( $user_ID ) {
$comment_args['include_unapproved'] = array( $user_ID );
} else {
$unapproved_email = wp_get_unapproved_comment_author_email();
if ( $unapproved_email ) {
$comment_args['include_unapproved'] = array( $unapproved_email );
}
$include_unapproved = wp_get_include_unapproved_comments_argument();
if ( $include_unapproved ) {
$comment_args['include_unapproved'] = $include_unapproved;
}
$per_page = 0;