mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +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:
@@ -1211,23 +1211,11 @@ function get_terms( $args = array(), $deprecated = '' ) {
|
||||
* False on failure.
|
||||
*/
|
||||
function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
|
||||
// Bail if term meta table is not installed.
|
||||
if ( get_option( 'db_version' ) < 34370 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( wp_term_is_shared( $term_id ) ) {
|
||||
return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
|
||||
}
|
||||
|
||||
$added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
|
||||
|
||||
// Bust term query cache.
|
||||
if ( $added ) {
|
||||
wp_cache_set( 'last_changed', microtime(), 'terms' );
|
||||
}
|
||||
|
||||
return $added;
|
||||
return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1241,19 +1229,7 @@ function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
|
||||
// Bail if term meta table is not installed.
|
||||
if ( get_option( 'db_version' ) < 34370 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value );
|
||||
|
||||
// Bust term query cache.
|
||||
if ( $deleted ) {
|
||||
wp_cache_set( 'last_changed', microtime(), 'terms' );
|
||||
}
|
||||
|
||||
return $deleted;
|
||||
return delete_metadata( 'term', $term_id, $meta_key, $meta_value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1268,11 +1244,6 @@ function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
|
||||
* @return mixed If `$single` is false, an array of metadata values. If `$single` is true, a single metadata value.
|
||||
*/
|
||||
function get_term_meta( $term_id, $key = '', $single = false ) {
|
||||
// Bail if term meta table is not installed.
|
||||
if ( get_option( 'db_version' ) < 34370 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return get_metadata( 'term', $term_id, $key, $single );
|
||||
}
|
||||
|
||||
@@ -1293,23 +1264,11 @@ function get_term_meta( $term_id, $key = '', $single = false ) {
|
||||
* WP_Error when term_id is ambiguous between taxonomies. False on failure.
|
||||
*/
|
||||
function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
|
||||
// Bail if term meta table is not installed.
|
||||
if ( get_option( 'db_version' ) < 34370 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( wp_term_is_shared( $term_id ) ) {
|
||||
return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
|
||||
}
|
||||
|
||||
$updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
|
||||
|
||||
// Bust term query cache.
|
||||
if ( $updated ) {
|
||||
wp_cache_set( 'last_changed', microtime(), 'terms' );
|
||||
}
|
||||
|
||||
return $updated;
|
||||
return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1324,11 +1283,6 @@ function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' )
|
||||
* @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
|
||||
*/
|
||||
function update_termmeta_cache( $term_ids ) {
|
||||
// Bail if term meta table is not installed.
|
||||
if ( get_option( 'db_version' ) < 34370 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
return update_meta_cache( 'term', $term_ids );
|
||||
}
|
||||
|
||||
@@ -1343,9 +1297,9 @@ function update_termmeta_cache( $term_ids ) {
|
||||
* @return array|false Array with meta data, or false when the meta table is not installed.
|
||||
*/
|
||||
function has_term_meta( $term_id ) {
|
||||
// Bail if term meta table is not installed.
|
||||
if ( get_option( 'db_version' ) < 34370 ) {
|
||||
return false;
|
||||
$check = wp_check_term_meta_support_prefilter( null );
|
||||
if ( null !== $check ) {
|
||||
return $check;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
@@ -4632,3 +4586,28 @@ function is_taxonomy_viewable( $taxonomy ) {
|
||||
|
||||
return $taxonomy->publicly_queryable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last changed time for the 'terms' cache group.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
function wp_cache_set_terms_last_changed() {
|
||||
wp_cache_set( 'last_changed', microtime(), 'terms' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Aborts calls to term meta if it is not supported.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param mixed $check Skip-value for whether to proceed term meta function execution.
|
||||
* @return mixed Original value of $check, or false if term meta is not supported.
|
||||
*/
|
||||
function wp_check_term_meta_support_prefilter( $check ) {
|
||||
if ( get_option( 'db_version' ) < 34370 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user