Make WordPress Core


Ignore:
Timestamp:
10/15/2018 11:45:16 AM (6 years ago)
Author:
flixos90
Message:

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.

Props flixos90, spacedmonkey.
Fixes #44467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/taxonomy.php

    r43510 r43729  
    11361136 */
    11371137function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
    1138     // Bail if term meta table is not installed.
    1139     if ( get_option( 'db_version' ) < 34370 ) {
    1140         return false;
    1141     }
    1142 
    11431138    if ( wp_term_is_shared( $term_id ) ) {
    11441139        return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id );
    11451140    }
    11461141
    1147     $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
    1148 
    1149     // Bust term query cache.
    1150     if ( $added ) {
    1151         wp_cache_set( 'last_changed', microtime(), 'terms' );
    1152     }
    1153 
    1154     return $added;
     1142    return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
    11551143}
    11561144
     
    11661154 */
    11671155function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
    1168     // Bail if term meta table is not installed.
    1169     if ( get_option( 'db_version' ) < 34370 ) {
    1170         return false;
    1171     }
    1172 
    1173     $deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value );
    1174 
    1175     // Bust term query cache.
    1176     if ( $deleted ) {
    1177         wp_cache_set( 'last_changed', microtime(), 'terms' );
    1178     }
    1179 
    1180     return $deleted;
     1156    return delete_metadata( 'term', $term_id, $meta_key, $meta_value );
    11811157}
    11821158
     
    11931169 */
    11941170function get_term_meta( $term_id, $key = '', $single = false ) {
    1195     // Bail if term meta table is not installed.
    1196     if ( get_option( 'db_version' ) < 34370 ) {
    1197         return false;
    1198     }
    1199 
    12001171    return get_metadata( 'term', $term_id, $key, $single );
    12011172}
     
    12181189 */
    12191190function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
    1220     // Bail if term meta table is not installed.
    1221     if ( get_option( 'db_version' ) < 34370 ) {
    1222         return false;
    1223     }
    1224 
    12251191    if ( wp_term_is_shared( $term_id ) ) {
    12261192        return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id );
    12271193    }
    12281194
    1229     $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
    1230 
    1231     // Bust term query cache.
    1232     if ( $updated ) {
    1233         wp_cache_set( 'last_changed', microtime(), 'terms' );
    1234     }
    1235 
    1236     return $updated;
     1195    return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
    12371196}
    12381197
     
    12491208 */
    12501209function update_termmeta_cache( $term_ids ) {
    1251     // Bail if term meta table is not installed.
    1252     if ( get_option( 'db_version' ) < 34370 ) {
    1253         return;
    1254     }
    1255 
    12561210    return update_meta_cache( 'term', $term_ids );
    12571211}
     
    12681222 */
    12691223function has_term_meta( $term_id ) {
    1270     // Bail if term meta table is not installed.
    1271     if ( get_option( 'db_version' ) < 34370 ) {
    1272         return false;
     1224    $check = wp_check_term_meta_support_prefilter( null );
     1225    if ( null !== $check ) {
     1226        return $check;
    12731227    }
    12741228
     
    43424296    return $parent;
    43434297}
     4298
     4299/**
     4300 * Sets the last changed time for the 'terms' cache group.
     4301 *
     4302 * @since 5.0.0
     4303 */
     4304function wp_cache_set_terms_last_changed() {
     4305    wp_cache_set( 'last_changed', microtime(), 'terms' );
     4306}
     4307
     4308/**
     4309 * Aborts calls to term meta if it is not supported.
     4310 *
     4311 * @since 5.0.0
     4312 *
     4313 * @param mixed $check Skip-value for whether to proceed term meta function execution.
     4314 * @return mixed Original value of $check, or false if term meta is not supported.
     4315 */
     4316function wp_check_term_meta_support_prefilter( $check ) {
     4317    if ( get_option( 'db_version' ) < 34370 ) {
     4318        return false;
     4319    }
     4320
     4321    return $check;
     4322}
Note: See TracChangeset for help on using the changeset viewer.