Make WordPress Core


Ignore:
Timestamp:
10/21/2015 04:25:31 PM (9 years ago)
Author:
boonebgorges
Message:

Don't force comment pagination.

[34561] instituted the policy of forcing pagination for comments. This strategy
was intended to avert problems when 'page_comments' is set to 0 - as it is by
default - and the number of comments on a given post rises into the hundreds or
thousands. By forcing pagination in all cases, we ensured that WordPress would
not time out by processing unwieldy numbers of comments on a given pageload.

The strategy proves problematic, however, because comment permalinks are
generated using the page of the comment. Forcing pagination for posts that
were not previously paginated would change the URL of all comments that do not
appear on the default comment page.

This changeset reintroduces the 'page_comments' setting and its corresponding
checkbox on Settings > Discussion. A number of tests, which were written after
[34561], are modified to work now that 'page_comments' will, once again, be
disabled by default.

See #8071.

File:
1 edited

Legend:

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

    r35013 r35331  
    707707    // No 'cpage' is provided, so we calculate one.
    708708    } else {
    709         if ( '' === $args['per_page'] ) {
     709        if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) {
    710710            $args['per_page'] = get_option('comments_per_page');
    711711        }
     
    12691269    $comment_args = array(
    12701270        'orderby' => 'comment_date_gmt',
     1271        'order' => 'ASC',
    12711272        'status'  => 'approve',
    12721273        'post_id' => $post->ID,
     
    12821283    }
    12831284
    1284     $per_page = (int) get_query_var( 'comments_per_page' );
    1285     if ( 0 === $per_page ) {
    1286         $per_page = (int) get_option( 'comments_per_page' );
    1287     }
    1288 
    1289     $comment_args['order']  = 'ASC';
    1290     $comment_args['number'] = $per_page;
    1291     $page = (int) get_query_var( 'cpage' );
    1292 
    1293     if ( $page ) {
    1294         $comment_args['offset'] = ( $page - 1 ) * $per_page;
    1295     } elseif ( 'oldest' === get_option( 'default_comments_page' ) ) {
    1296         $comment_args['offset'] = 0;
    1297     } else {
    1298         // If fetching the first page of 'newest', we need a top-level comment count.
    1299         $top_level_query = new WP_Comment_Query();
    1300         $top_level_count = $top_level_query->query( array(
    1301             'count'   => true,
    1302             'orderby' => false,
    1303             'post_id' => $post->ID,
    1304             'parent'  => 0,
    1305         ) );
    1306 
    1307         $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
     1285    $per_page = 0;
     1286    if ( get_option( 'page_comments' ) ) {
     1287        $per_page = (int) get_query_var( 'comments_per_page' );
     1288        if ( 0 === $per_page ) {
     1289            $per_page = (int) get_option( 'comments_per_page' );
     1290        }
     1291
     1292        $comment_args['number'] = $per_page;
     1293        $page = (int) get_query_var( 'cpage' );
     1294
     1295        if ( $page ) {
     1296            $comment_args['offset'] = ( $page - 1 ) * $per_page;
     1297        } elseif ( 'oldest' === get_option( 'default_comments_page' ) ) {
     1298            $comment_args['offset'] = 0;
     1299        } else {
     1300            // If fetching the first page of 'newest', we need a top-level comment count.
     1301            $top_level_query = new WP_Comment_Query();
     1302            $top_level_count = $top_level_query->query( array(
     1303                'count'   => true,
     1304                'orderby' => false,
     1305                'post_id' => $post->ID,
     1306                'parent'  => 0,
     1307            ) );
     1308
     1309            $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
     1310        }
    13081311    }
    13091312
     
    13461349
    13471350    $overridden_cpage = false;
    1348     if ( '' == get_query_var('cpage') ) {
     1351    if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) {
    13491352        set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
    13501353        $overridden_cpage = true;
     
    19421945    }
    19431946
    1944     if ( '' === $r['per_page'] )
     1947    if ( '' === $r['per_page'] && get_option( 'page_comments' ) ) {
    19451948        $r['per_page'] = get_query_var('comments_per_page');
     1949    }
    19461950
    19471951    if ( empty($r['per_page']) ) {
Note: See TracChangeset for help on using the changeset viewer.