Invalidate comment query cache when modifying comment meta.

Comment queries are sensitive to comment meta due to the `meta_query`
parameter, so the cache must be invalidated when comment meta is changed,
added, or deleted.

Props spacedmonkey.
See #40669.

git-svn-id: https://develop.svn.wordpress.org/trunk@41848 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2017-10-12 14:58:58 +00:00
parent ee44859ee4
commit 6ce4e413ce
2 changed files with 150 additions and 3 deletions

View File

@@ -423,7 +423,11 @@ function get_comment_count( $post_id = 0 ) {
* @return int|bool Meta ID on success, false on failure.
*/
function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) {
return add_metadata('comment', $comment_id, $meta_key, $meta_value, $unique);
$added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
if ( $added ) {
wp_cache_set( 'last_changed', microtime(), 'comment' );
}
return $added;
}
/**
@@ -442,7 +446,11 @@ function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false)
* @return bool True on success, false on failure.
*/
function delete_comment_meta($comment_id, $meta_key, $meta_value = '') {
return delete_metadata('comment', $comment_id, $meta_key, $meta_value);
$deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
if ( $deleted ) {
wp_cache_set( 'last_changed', microtime(), 'comment' );
}
return $deleted;
}
/**
@@ -479,7 +487,11 @@ function get_comment_meta($comment_id, $key = '', $single = false) {
* @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
*/
function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '') {
return update_metadata('comment', $comment_id, $meta_key, $meta_value, $prev_value);
$updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
if ( $updated ) {
wp_cache_set( 'last_changed', microtime(), 'comment' );
}
return $updated;
}
/**