Make WordPress Core


Ignore:
Timestamp:
01/20/2016 04:32:22 AM (11 years ago)
Author:
dd32
Message:

Comments: In comments_template(), don't run hierarchical queries if comment threading is disabled.

When hierarchical=true, WP_Comment_Query will always fetch comments according to the comment hierarchy, even if 'thread_comments' is disabled for the site.
This can cause problems when comment threading is disabled after threaded comments have been recorded on the site; comments will no longer be returned in a strictly chronological order.
We address the issue by refraining from querying hierarchically when comment threading is disabled.

Merges [36226] to the 4.4 branch.
Props jmdodd.
Fixes #35378.

Location:
branches/4.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

  • branches/4.4/src/wp-includes/comment-template.php

    r36158 r36353  
    12861286                'status'  => 'approve',
    12871287                'post_id' => $post->ID,
    1288                 'hierarchical' => 'threaded',
    12891288                'no_found_rows' => false,
    12901289                'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
    12911290        );
     1291
     1292        if ( get_option('thread_comments') ) {
     1293                $comment_args['hierarchical'] = 'threaded';
     1294        } else {
     1295                $comment_args['hierarchical'] = false;
     1296        }
    12921297
    12931298        if ( $user_ID ) {
    … …  
    13361341
    13371342        // Trees must be flattened before they're passed to the walker.
    1338         $comments_flat = array();
    1339         foreach ( $_comments as $_comment ) {
    1340                 $comments_flat[]  = $_comment;
    1341                 $comment_children = $_comment->get_children( array(
    1342                         'format' => 'flat',
    1343                         'status' => $comment_args['status'],
    1344                         'orderby' => $comment_args['orderby']
    1345                 ) );
    1346 
    1347                 foreach ( $comment_children as $comment_child ) {
    1348                         $comments_flat[] = $comment_child;
     1343        if ( $comment_args['hierarchical'] ) {
     1344                $comments_flat = array();
     1345                foreach ( $_comments as $_comment ) {
     1346                        $comments_flat[]  = $_comment;
     1347                        $comment_children = $_comment->get_children( array(
     1348                                'format' => 'flat',
     1349                                'status' => $comment_args['status'],
     1350                                'orderby' => $comment_args['orderby']
     1351                        ) );
     1352
     1353                        foreach ( $comment_children as $comment_child ) {
     1354                                $comments_flat[] = $comment_child;
     1355                        }
    13491356                }
     1357        } else {
     1358                $comments_flat = $_comments;
    13501359        }
    13511360
Note: See TracChangeset for help on using the changeset viewer.