From c231add9fe731075022f93069d6c293c0c5f9efc Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 5 Sep 2015 22:25:24 +0000 Subject: [PATCH] In `wp_list_comments()`, update the comment meta cache when the comments derive from `WP_Query` and the new `->comment_meta_cached` prop is `false`. There are no uses of `wp_list_comments()` in Core where `$comments` are passed as the 2nd argument. Adds unit tests. Props wonderboymusic, bradt. Fixes #16894. Built from https://develop.svn.wordpress.org/trunk@33925 git-svn-id: http://core.svn.wordpress.org/trunk@33894 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 6 ++++++ wp-includes/query.php | 9 +++++++++ wp-includes/version.php | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index 8c4c60e520..5c59348fc5 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -2116,6 +2116,12 @@ function wp_list_comments( $args = array(), $comments = null ) { } else { $_comments = $wp_query->comments; } + + if ( ! $wp_query->comment_meta_cached ) { + $comment_ids = wp_list_pluck( $_comments, 'comment_ID' ); + update_meta_cache( 'comment', $comment_ids ); + $wp_query->comment_meta_cached = true; + } } if ( '' === $r['per_page'] && get_option('page_comments') ) diff --git a/wp-includes/query.php b/wp-includes/query.php index 4abfa2da11..0d45bcbbf8 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1292,6 +1292,15 @@ class WP_Query { */ public $thumbnails_cached = false; + /** + * Set if comment meta has already been cached + * + * @since 4.4.0 + * @access public + * @var bool + */ + public $comment_meta_cached = false; + /** * Cached list of search stopwords. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 808ae63b46..ab00e3eefe 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-33924'; +$wp_version = '4.4-alpha-33925'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.