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

@@ -94,7 +94,7 @@ class WP_Comment_Query {
*
* @since 4.2.0
* @since 4.4.0 `$parent__in` and `$parent__not_in` were added.
* @since 4.4.0 Order by `comment__in` was added.
* @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache` was added.
* @access public
*
* @param string|array $query {
@@ -161,6 +161,8 @@ class WP_Comment_Query {
* @type array $type__in Include comments from a given array of comment types. Default empty.
* @type array $type__not_in Exclude comments from a given array of comment types. Default empty.
* @type int $user_id Include comments for a specific user ID. Default empty.
* @type bool $update_comment_meta_cache Whether to prime the metadata cache for found comments.
* Default true.
* }
*/
public function __construct( $query = '' ) {
@@ -201,6 +203,7 @@ class WP_Comment_Query {
'meta_value' => '',
'meta_query' => '',
'date_query' => null, // See WP_Date_Query
'update_comment_meta_cache' => true,
);
if ( ! empty( $query ) ) {
@@ -698,7 +701,7 @@ class WP_Comment_Query {
wp_cache_add( $cache_key, $comments, 'comment' );
if ( '*' === $fields ) {
update_comment_cache( $comments );
update_comment_cache( $comments, $this->query_vars['update_comment_meta_cache'] );
}
$this->comments = $comments;