From ff7df78e04bf867a98c0378f86bc4c5bab88ad3b Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 25 Sep 2015 13:47:25 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@34538 git-svn-id: http://core.svn.wordpress.org/trunk@34502 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy-functions.php | 27 ++++++++++++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/wp-includes/taxonomy-functions.php b/wp-includes/taxonomy-functions.php index 59fc9a0bf1..3d091e9165 100644 --- a/wp-includes/taxonomy-functions.php +++ b/wp-includes/taxonomy-functions.php @@ -1488,7 +1488,14 @@ function get_terms( $taxonomies, $args = '' ) { * @return int|bool Meta ID on success, false on failure. */ function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) { - return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); + $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; } /** @@ -1502,7 +1509,14 @@ 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 = '' ) { - return delete_metadata( 'term', $term_id, $meta_key, $meta_value ); + $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; } /** @@ -1536,7 +1550,14 @@ function get_term_meta( $term_id, $key = '', $single = false ) { * @return int|bool Meta ID if the key didn't previously exist. True on successful update. False on failure. */ function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) { - return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); + $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; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index d0ee4591d5..4971c91969 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34537'; +$wp_version = '4.4-alpha-34538'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.