mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 07:40:07 +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:
@@ -613,6 +613,23 @@ function get_metadata_by_mid( $meta_type, $meta_id ) {
|
||||
|
||||
$id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id';
|
||||
|
||||
/**
|
||||
* Filters whether to retrieve metadata of a specific type by meta ID.
|
||||
*
|
||||
* The dynamic portion of the hook, `$meta_type`, refers to the meta
|
||||
* object type (comment, post, term, or user). Returning a non-null value
|
||||
* will effectively short-circuit the function.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param mixed $value The value get_metadata_by_mid() should return.
|
||||
* @param int $meta_id Meta ID.
|
||||
*/
|
||||
$check = apply_filters( "get_{$meta_type}_metadata_by_mid", null, $meta_id );
|
||||
if ( null !== $check ) {
|
||||
return $check;
|
||||
}
|
||||
|
||||
$meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) );
|
||||
|
||||
if ( empty( $meta ) ) {
|
||||
@@ -660,6 +677,25 @@ function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key =
|
||||
$column = sanitize_key( $meta_type . '_id' );
|
||||
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
|
||||
|
||||
/**
|
||||
* Filters whether to update metadata of a specific type by meta ID.
|
||||
*
|
||||
* The dynamic portion of the hook, `$meta_type`, refers to the meta
|
||||
* object type (comment, post, term, or user). Returning a non-null value
|
||||
* will effectively short-circuit the function.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param null|bool $check Whether to allow updating metadata for the given type.
|
||||
* @param int $meta_id Meta ID.
|
||||
* @param mixed $meta_value Meta value. Must be serializable if non-scalar.
|
||||
* @param string|bool $meta_key Meta key, if provided.
|
||||
*/
|
||||
$check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key );
|
||||
if ( null !== $check ) {
|
||||
return (bool) $check;
|
||||
}
|
||||
|
||||
// Fetch the meta and go on if it's found.
|
||||
if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
|
||||
$original_key = $meta->meta_key;
|
||||
@@ -755,6 +791,23 @@ function delete_metadata_by_mid( $meta_type, $meta_id ) {
|
||||
$column = sanitize_key( $meta_type . '_id' );
|
||||
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
|
||||
|
||||
/**
|
||||
* Filters whether to delete metadata of a specific type by meta ID.
|
||||
*
|
||||
* The dynamic portion of the hook, `$meta_type`, refers to the meta
|
||||
* object type (comment, post, term, or user). Returning a non-null value
|
||||
* will effectively short-circuit the function.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param null|bool $delete Whether to allow metadata deletion of the given type.
|
||||
* @param int $meta_id Meta ID.
|
||||
*/
|
||||
$check = apply_filters( "delete_{$meta_type}_metadata_by_mid", null, $meta_id );
|
||||
if ( null !== $check ) {
|
||||
return (bool) $check;
|
||||
}
|
||||
|
||||
// Fetch the meta and go on if it's found.
|
||||
if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
|
||||
$object_id = $meta->{$column};
|
||||
@@ -841,6 +894,23 @@ function update_meta_cache( $meta_type, $object_ids ) {
|
||||
|
||||
$object_ids = array_map( 'intval', $object_ids );
|
||||
|
||||
/**
|
||||
* Filters whether to update the metadata cache of a specific type.
|
||||
*
|
||||
* The dynamic portion of the hook, `$meta_type`, refers to the meta
|
||||
* object type (comment, post, term, or user). Returning a non-null value
|
||||
* will effectively short-circuit the function.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param mixed $check Whether to allow updating the meta cache of the given type.
|
||||
* @param array $object_ids Array of object IDs to update the meta cache for.
|
||||
*/
|
||||
$check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids );
|
||||
if ( null !== $check ) {
|
||||
return (bool) $check;
|
||||
}
|
||||
|
||||
$cache_key = $meta_type . '_meta';
|
||||
$ids = array();
|
||||
$cache = array();
|
||||
|
||||
Reference in New Issue
Block a user