REST API: Move object type-specific metadata integrations from the wrapper functions to the low-level Meta API functions.

Object type-specific actions that should happen before or after modification of metadata have so far been part of the respective wrapper functions. By using action and filter hooks, this changeset ensures they are always executed, even when calling the lower-level Meta API functions directly, which the REST API does as a prime example.

Merges [43729] to trunk.

Props flixos90, spacedmonkey.
Fixes #44467.


git-svn-id: https://develop.svn.wordpress.org/trunk@43982 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jeremy Felt
2018-12-12 03:02:00 +00:00
parent 1c9f359857
commit 2ad4d85ed5
8 changed files with 287 additions and 90 deletions

View File

@@ -442,11 +442,7 @@ 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 ) {
$added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
if ( $added ) {
wp_cache_set( 'last_changed', microtime(), 'comment' );
}
return $added;
return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
}
/**
@@ -465,11 +461,7 @@ 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 = '' ) {
$deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
if ( $deleted ) {
wp_cache_set( 'last_changed', microtime(), 'comment' );
}
return $deleted;
return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
}
/**
@@ -506,11 +498,7 @@ 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 = '' ) {
$updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
if ( $updated ) {
wp_cache_set( 'last_changed', microtime(), 'comment' );
}
return $updated;
return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
}
/**
@@ -3512,3 +3500,12 @@ function wp_comments_personal_data_eraser( $email_address, $page = 1 ) {
'done' => $done,
);
}
/**
* Sets the last changed time for the 'comment' cache group.
*
* @since 5.0.0
*/
function wp_cache_set_comments_last_changed() {
wp_cache_set( 'last_changed', microtime(), 'comment' );
}