Make WordPress Core


Ignore:
Timestamp:
12/12/2018 03:02:00 AM (7 years ago)
Author:
jeremyfelt
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.

Merges [43729] to trunk.

Props flixos90, spacedmonkey.
Fixes #44467.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/taxonomy.php

    r43631 r43982  
    12121212 */
    12131213function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
    1214     // Bail if term meta table is not installed.
    1215     if ( get_option( 'db_version' ) < 34370 ) {
    1216         return false;
    1217     }
    1218 
    12191214    if ( wp_term_is_shared( $term_id ) ) {
    12201215        return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
    12211216    }
    12221217
    1223     $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
    1224 
    1225     // Bust term query cache.
    1226     if ( $added ) {
    1227         wp_cache_set( 'last_changed', microtime(), 'terms' );
    1228     }
    1229 
    1230     return $added;
     1218    return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
    12311219}
    12321220
     
    12421230 */
    12431231function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
    1244     // Bail if term meta table is not installed.
    1245     if ( get_option( 'db_version' ) < 34370 ) {
    1246         return false;
    1247     }
    1248 
    1249     $deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value );
    1250 
    1251     // Bust term query cache.
    1252     if ( $deleted ) {
    1253         wp_cache_set( 'last_changed', microtime(), 'terms' );
    1254     }
    1255 
    1256     return $deleted;
     1232    return delete_metadata( 'term', $term_id, $meta_key, $meta_value );
    12571233}
    12581234
     
    12691245 */
    12701246function get_term_meta( $term_id, $key = '', $single = false ) {
    1271     // Bail if term meta table is not installed.
    1272     if ( get_option( 'db_version' ) < 34370 ) {
    1273         return false;
    1274     }
    1275 
    12761247    return get_metadata( 'term', $term_id, $key, $single );
    12771248}
     
    12941265 */
    12951266function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
    1296     // Bail if term meta table is not installed.
    1297     if ( get_option( 'db_version' ) < 34370 ) {
    1298         return false;
    1299     }
    1300 
    13011267    if ( wp_term_is_shared( $term_id ) ) {
    13021268        return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
    13031269    }
    13041270
    1305     $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
    1306 
    1307     // Bust term query cache.
    1308     if ( $updated ) {
    1309         wp_cache_set( 'last_changed', microtime(), 'terms' );
    1310     }
    1311 
    1312     return $updated;
     1271    return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
    13131272}
    13141273
     
    13251284 */
    13261285function update_termmeta_cache( $term_ids ) {
    1327     // Bail if term meta table is not installed.
    1328     if ( get_option( 'db_version' ) < 34370 ) {
    1329         return;
    1330     }
    1331 
    13321286    return update_meta_cache( 'term', $term_ids );
    13331287}
     
    13441298 */
    13451299function has_term_meta( $term_id ) {
    1346     // Bail if term meta table is not installed.
    1347     if ( get_option( 'db_version' ) < 34370 ) {
    1348         return false;
     1300    $check = wp_check_term_meta_support_prefilter( null );
     1301    if ( null !== $check ) {
     1302        return $check;
    13491303    }
    13501304
     
    46334587    return $taxonomy->publicly_queryable;
    46344588}
     4589
     4590/**
     4591 * Sets the last changed time for the 'terms' cache group.
     4592 *
     4593 * @since 5.0.0
     4594 */
     4595function wp_cache_set_terms_last_changed() {
     4596    wp_cache_set( 'last_changed', microtime(), 'terms' );
     4597}
     4598
     4599/**
     4600 * Aborts calls to term meta if it is not supported.
     4601 *
     4602 * @since 5.0.0
     4603 *
     4604 * @param mixed $check Skip-value for whether to proceed term meta function execution.
     4605 * @return mixed Original value of $check, or false if term meta is not supported.
     4606 */
     4607function wp_check_term_meta_support_prefilter( $check ) {
     4608    if ( get_option( 'db_version' ) < 34370 ) {
     4609        return false;
     4610    }
     4611
     4612    return $check;
     4613}
Note: See TracChangeset for help on using the changeset viewer.