mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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:
@@ -1906,15 +1906,12 @@ function get_posts( $args = null ) {
|
||||
*/
|
||||
function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
|
||||
// Make sure meta is added to the post, not a revision.
|
||||
if ( $the_post = wp_is_post_revision( $post_id ) ) {
|
||||
$the_post = wp_is_post_revision( $post_id );
|
||||
if ( $the_post ) {
|
||||
$post_id = $the_post;
|
||||
}
|
||||
|
||||
$added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
|
||||
if ( $added ) {
|
||||
wp_cache_set( 'last_changed', microtime(), 'posts' );
|
||||
}
|
||||
return $added;
|
||||
return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1934,15 +1931,12 @@ function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
|
||||
*/
|
||||
function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
|
||||
// Make sure meta is added to the post, not a revision.
|
||||
if ( $the_post = wp_is_post_revision( $post_id ) ) {
|
||||
$the_post = wp_is_post_revision( $post_id );
|
||||
if ( $the_post ) {
|
||||
$post_id = $the_post;
|
||||
}
|
||||
|
||||
$deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value );
|
||||
if ( $deleted ) {
|
||||
wp_cache_set( 'last_changed', microtime(), 'posts' );
|
||||
}
|
||||
return $deleted;
|
||||
return delete_metadata( 'post', $post_id, $meta_key, $meta_value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1981,15 +1975,12 @@ function get_post_meta( $post_id, $key = '', $single = false ) {
|
||||
*/
|
||||
function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
|
||||
// Make sure meta is added to the post, not a revision.
|
||||
if ( $the_post = wp_is_post_revision( $post_id ) ) {
|
||||
$the_post = wp_is_post_revision( $post_id );
|
||||
if ( $the_post ) {
|
||||
$post_id = $the_post;
|
||||
}
|
||||
|
||||
$updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
|
||||
if ( $updated ) {
|
||||
wp_cache_set( 'last_changed', microtime(), 'posts' );
|
||||
}
|
||||
return $updated;
|
||||
return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2001,11 +1992,7 @@ function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' )
|
||||
* @return bool Whether the post meta key was deleted from the database.
|
||||
*/
|
||||
function delete_post_meta_by_key( $post_meta_key ) {
|
||||
$deleted = delete_metadata( 'post', null, $post_meta_key, '', true );
|
||||
if ( $deleted ) {
|
||||
wp_cache_set( 'last_changed', microtime(), 'posts' );
|
||||
}
|
||||
return $deleted;
|
||||
return delete_metadata( 'post', null, $post_meta_key, '', true );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -6785,3 +6772,12 @@ function _filter_query_attachment_filenames( $clauses ) {
|
||||
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last changed time for the 'posts' cache group.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
function wp_cache_set_posts_last_changed() {
|
||||
wp_cache_set( 'last_changed', microtime(), 'posts' );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user