WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/25/2015 01:46:36 PM (5 years ago)
Author:
boonebgorges
Message:

Bust term query cache when modifying term meta.

The 'last_changed' incrementor is used to invalidate the get_terms() query
cache. Since get_terms() queries may reference 'meta_query', changing term
metadata could change the results of the queries. So we invalidate the cache
on add, delete, and update.

See #10142.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy-functions.php

    r34534 r34538  
    14891489 */
    14901490function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
    1491     return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
     1491    $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
     1492
     1493    // Bust term query cache.
     1494    if ( $added ) {
     1495        wp_cache_set( 'last_changed', microtime(), 'terms' );
     1496    }
     1497
     1498    return $added;
    14921499}
    14931500
     
    15031510 */
    15041511function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
    1505     return delete_metadata( 'term', $term_id, $meta_key, $meta_value );
     1512    $deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value );
     1513
     1514    // Bust term query cache.
     1515    if ( $deleted ) {
     1516        wp_cache_set( 'last_changed', microtime(), 'terms' );
     1517    }
     1518
     1519    return $deleted;
    15061520}
    15071521
     
    15371551 */
    15381552function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
    1539     return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
     1553    $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
     1554
     1555    // Bust term query cache.
     1556    if ( $updated ) {
     1557        wp_cache_set( 'last_changed', microtime(), 'terms' );
     1558    }
     1559
     1560    return $updated;
    15401561}
    15411562
Note: See TracChangeset for help on using the changeset viewer.