Introduce `clean_taxonomy_cache()` function.

Previously, taxonomy-wide caches were cleaned only inside of
`clean_term_cache()`. This made it hard to clean taxonmy caches
in isolation from specific taxonomy terms.

Props spacedmonkey.
See #37189.
Built from https://develop.svn.wordpress.org/trunk@40919


git-svn-id: http://core.svn.wordpress.org/trunk@40769 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2017-06-21 04:04:41 +00:00
parent f730861b90
commit 989427d598
2 changed files with 27 additions and 6 deletions

View File

@ -3003,11 +3003,7 @@ function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
foreach ( $taxonomies as $taxonomy ) {
if ( $clean_taxonomy ) {
wp_cache_delete('all_ids', $taxonomy);
wp_cache_delete('get', $taxonomy);
delete_option("{$taxonomy}_children");
// Regenerate {$taxonomy}_children
_get_term_hierarchy($taxonomy);
clean_taxonomy_cache( $taxonomy );
}
/**
@ -3026,6 +3022,31 @@ function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
wp_cache_set( 'last_changed', microtime(), 'terms' );
}
/**
* Clean the caches for a taxonomy.
*
* @since 4.9.0
*
* @param string $taxonomy Taxonomy slug.
*/
function clean_taxonomy_cache( $taxonomy ) {
wp_cache_delete( 'all_ids', $taxonomy );
wp_cache_delete( 'get', $taxonomy );
// Regenerate cached hierarchy.
delete_option( "{$taxonomy}_children" );
_get_term_hierarchy( $taxonomy );
/**
* Fires after a taxonomy's caches have been cleaned.
*
* @since 4.9.0
*
* @param string $taxonomy Taxonomy slug.
*/
do_action( 'clean_taxonomy_cache', $taxonomy );
}
/**
* Retrieves the taxonomy relationship to the term object id.
*

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-40918';
$wp_version = '4.9-alpha-40919';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.