Make WordPress Core

Changeset 34669

Timestamp:
09/28/2015 07:29:22 PM (9 years ago)
Author:
boonebgorges
Message:

Fix comment_order for single page comment threads.

The old comment pagination logic had a separate block for comment threads that
appeared on a single page. After the refactoring in [34561], all comment
pagination logic is unified.

This change ensures that 'comment_order' is respected in all scenarios.

Fixes #8071.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r34569 r34669  
    12341234    }
    12351235
    1236     $flip_comment_order = $trim_comments_on_page = false;
    1237     if ( $post->comment_count > $per_page ) {
    1238         $comment_args['number'] = $per_page;
    1239 
    1240         /*
    1241          * For legacy reasons, higher page numbers always mean more recent comments, regardless of sort order.
    1242          * Since we don't have full pagination info until after the query, we use some tricks to get the
    1243          * right comments for the current page.
    1244          *
    1245          * Abandon all hope, ye who enter here!
    1246          */
    1247         $page = (int) get_query_var( 'cpage' );
    1248         if ( 'newest' === get_option( 'default_comments_page' ) ) {
    1249             if ( $page ) {
    1250                 $comment_args['order'] = 'ASC';
    1251 
    1252                 /*
    1253                  * We don't have enough data (namely, the total number of comments) to calculate an
    1254                  * exact offset. We'll fetch too many comments, and trim them as needed
    1255                  * after the query.
    1256                  */
    1257                 $offset = ( $page - 2 ) * $per_page;
    1258                 if ( 0 > $offset ) {
    1259                     // `WP_Comment_Query` doesn't support negative offsets.
    1260                     $comment_args['offset'] = 0;
    1261                 } else {
    1262                     $comment_args['offset'] = $offset;
    1263                 }
    1264 
    1265                 // Fetch double the number of comments we need.
    1266                 $comment_args['number'] += $per_page;
    1267                 $trim_comments_on_page = true;
     1236    /*
     1237     * For legacy reasons, higher page numbers always mean more recent comments, regardless of sort order.
     1238     * Since we don't have full pagination info until after the query, we use some tricks to get the
     1239     * right comments for the current page.
     1240     *
     1241     * Abandon all hope, ye who enter here!
     1242     */
     1243    $flip_comment_order = $trim_comments_on_page= false;
     1244    $comment_args['number'] = $per_page;
     1245    $page = (int) get_query_var( 'cpage' );
     1246    if ( 'newest' === get_option( 'default_comments_page' ) ) {
     1247        if ( $page ) {
     1248            $comment_args['order'] = 'ASC';
     1249
     1250            /*
     1251             * We don't have enough data (namely, the total number of comments) to calculate an
     1252             * exact offset. We'll fetch too many comments, and trim them as needed
     1253             * after the query.
     1254             */
     1255            $offset = ( $page - 2 ) * $per_page;
     1256            if ( 0 > $offset ) {
     1257                // `WP_Comment_Query` doesn't support negative offsets.
     1258                $comment_args['offset'] = 0;
    12681259            } else {
    1269                 $comment_args['order'] = 'DESC';
    1270                 $comment_args['offset'] = 0;
    1271                 $flip_comment_order = true;
     1260                $comment_args['offset'] = $offset;
    12721261            }
     1262
     1263
     1264
     1265
    12731266        } else {
    1274             $comment_args['order'] = 'ASC';
    1275             if ( $page ) {
    1276                 $comment_args['offset'] = ( $page - 1 ) * $per_page;
    1277             } else {
    1278                 $comment_args['offset'] = 0;
    1279             }
     1267            $comment_args['order'] = 'DESC';
     1268            $comment_args['offset'] = 0;
     1269            $flip_comment_order = true;
     1270        }
     1271    } else {
     1272        $comment_args['order'] = 'ASC';
     1273        if ( $page ) {
     1274            $comment_args['offset'] = ( $page - 1 ) * $per_page;
     1275        } else {
     1276            $comment_args['offset'] = 0;
    12801277        }
    12811278    }
     
    12841281    $_comments = $comment_query->comments;
    12851282
    1286     // Delightful pagination quirk #1: first page of results sometimes needs reordering.
     1283    // Delightful pagination quirk #1: ng.
    12871284    if ( $flip_comment_order ) {
    12881285        $_comments = array_reverse( $_comments );
Note: See TracChangeset for help on using the changeset viewer.