From 13629bf5d055f804d4c80d916386295c9168c40c Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 8 Jan 2016 22:17:26 +0000 Subject: [PATCH] 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. Props jmdodd. Fixes #35378. Built from https://develop.svn.wordpress.org/trunk@36226 git-svn-id: http://core.svn.wordpress.org/trunk@36193 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 31 ++++++++++++++++++++----------- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index f4c904bc88..64b4ba8e53 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -1286,11 +1286,16 @@ function comments_template( $file = '/comments.php', $separate_comments = false 'order' => 'ASC', 'status' => 'approve', 'post_id' => $post->ID, - 'hierarchical' => 'threaded', 'no_found_rows' => false, '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 ) { $comment_args['include_unapproved'] = array( $user_ID ); } elseif ( ! empty( $comment_author_email ) ) { @@ -1336,18 +1341,22 @@ function comments_template( $file = '/comments.php', $separate_comments = false $_comments = $comment_query->comments; // Trees must be flattened before they're passed to the walker. - $comments_flat = array(); - foreach ( $_comments as $_comment ) { - $comments_flat[] = $_comment; - $comment_children = $_comment->get_children( array( - 'format' => 'flat', - 'status' => $comment_args['status'], - 'orderby' => $comment_args['orderby'] - ) ); + if ( $comment_args['hierarchical'] ) { + $comments_flat = array(); + foreach ( $_comments as $_comment ) { + $comments_flat[] = $_comment; + $comment_children = $_comment->get_children( array( + 'format' => 'flat', + 'status' => $comment_args['status'], + 'orderby' => $comment_args['orderby'] + ) ); - foreach ( $comment_children as $comment_child ) { - $comments_flat[] = $comment_child; + foreach ( $comment_children as $comment_child ) { + $comments_flat[] = $comment_child; + } } + } else { + $comments_flat = $_comments; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index abc701c68f..9cc96045ce 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36225'; +$wp_version = '4.5-alpha-36226'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.