WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/21/2015 03:06:41 AM (3 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-template.php

    r35933 r36040  
    13141314            // If fetching the first page of 'newest', we need a top-level comment count.
    13151315            $top_level_query = new WP_Comment_Query();
    1316             $top_level_count = $top_level_query->query( array(
     1316            $top_level_args  = array(
    13171317                'count'   => true,
    13181318                'orderby' => false,
    13191319                'post_id' => $post->ID,
    13201320                'parent'  => 0,
    1321             ) );
     1321                'status'  => 'approve',
     1322            );
     1323
     1324            if ( isset( $comment_args['include_unapproved'] ) ) {
     1325                $top_level_args['include_unapproved'] = $comment_args['include_unapproved'];
     1326            }
     1327
     1328            $top_level_count = $top_level_query->query( $top_level_args );
    13221329
    13231330            $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
Note: See TracChangeset for help on using the changeset viewer.