Prime comment meta caches in WP_Comment_Query.

The new 'update_comment_meta_cache' parameter, which defaults to `true`, can
be used to disable this behavior.

`update_comment_cache()` has been updated to support an `$update_meta_cache`
parameter, which also updates to true; this matches the pattern we use for
priming post caches.

See #16894.

git-svn-id: https://develop.svn.wordpress.org/trunk@34268 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-09-17 19:29:46 +00:00
parent b08a176488
commit 12329f5ef8
3 changed files with 95 additions and 4 deletions

View File

@@ -2357,12 +2357,23 @@ function clean_comment_cache($ids) {
* cache using the comment group with the key using the ID of the comments.
*
* @since 2.3.0
* @since 4.4.0 Introduced the `$update_meta_cache` parameter.
*
* @param array $comments Array of comment row objects
* @param array $comments Array of comment row objects
* @param bool $update_meta_cache Whether to update commentmeta cache. Default true.
*/
function update_comment_cache($comments) {
function update_comment_cache( $comments, $update_meta_cache = true ) {
foreach ( (array) $comments as $comment )
wp_cache_add($comment->comment_ID, $comment, 'comment');
if ( $update_meta_cache ) {
// Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
$comment_ids = array();
foreach ( $comments as $comment ) {
$comment_ids[] = $comment->comment_ID;
}
update_meta_cache( 'comment', $comment_ids );
}
}
//