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. Built from https://develop.svn.wordpress.org/branches/4.4@36353 git-svn-id: http://core.svn.wordpress.org/branches/4.4@36320 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3a05448edf
commit
7b2cd6dbd9
|
@ -1285,11 +1285,16 @@ function comments_template( $file = '/comments.php', $separate_comments = false
|
||||||
'order' => 'ASC',
|
'order' => 'ASC',
|
||||||
'status' => 'approve',
|
'status' => 'approve',
|
||||||
'post_id' => $post->ID,
|
'post_id' => $post->ID,
|
||||||
'hierarchical' => 'threaded',
|
|
||||||
'no_found_rows' => false,
|
'no_found_rows' => false,
|
||||||
'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
|
'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ( get_option('thread_comments') ) {
|
||||||
|
$comment_args['hierarchical'] = 'threaded';
|
||||||
|
} else {
|
||||||
|
$comment_args['hierarchical'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
if ( $user_ID ) {
|
if ( $user_ID ) {
|
||||||
$comment_args['include_unapproved'] = array( $user_ID );
|
$comment_args['include_unapproved'] = array( $user_ID );
|
||||||
} elseif ( ! empty( $comment_author_email ) ) {
|
} elseif ( ! empty( $comment_author_email ) ) {
|
||||||
|
@ -1335,18 +1340,22 @@ function comments_template( $file = '/comments.php', $separate_comments = false
|
||||||
$_comments = $comment_query->comments;
|
$_comments = $comment_query->comments;
|
||||||
|
|
||||||
// Trees must be flattened before they're passed to the walker.
|
// Trees must be flattened before they're passed to the walker.
|
||||||
$comments_flat = array();
|
if ( $comment_args['hierarchical'] ) {
|
||||||
foreach ( $_comments as $_comment ) {
|
$comments_flat = array();
|
||||||
$comments_flat[] = $_comment;
|
foreach ( $_comments as $_comment ) {
|
||||||
$comment_children = $_comment->get_children( array(
|
$comments_flat[] = $_comment;
|
||||||
'format' => 'flat',
|
$comment_children = $_comment->get_children( array(
|
||||||
'status' => $comment_args['status'],
|
'format' => 'flat',
|
||||||
'orderby' => $comment_args['orderby']
|
'status' => $comment_args['status'],
|
||||||
) );
|
'orderby' => $comment_args['orderby']
|
||||||
|
) );
|
||||||
|
|
||||||
foreach ( $comment_children as $comment_child ) {
|
foreach ( $comment_children as $comment_child ) {
|
||||||
$comments_flat[] = $comment_child;
|
$comments_flat[] = $comment_child;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$comments_flat = $_comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue