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.

git-svn-id: https://develop.svn.wordpress.org/trunk@40919 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2017-06-21 04:03:22 +00:00
parent deae2f7cbf
commit a529129de5

View File

@ -3003,11 +3003,7 @@ function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
foreach ( $taxonomies as $taxonomy ) { foreach ( $taxonomies as $taxonomy ) {
if ( $clean_taxonomy ) { if ( $clean_taxonomy ) {
wp_cache_delete('all_ids', $taxonomy); clean_taxonomy_cache( $taxonomy );
wp_cache_delete('get', $taxonomy);
delete_option("{$taxonomy}_children");
// Regenerate {$taxonomy}_children
_get_term_hierarchy($taxonomy);
} }
/** /**
@ -3026,6 +3022,31 @@ function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
wp_cache_set( 'last_changed', microtime(), 'terms' ); 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. * Retrieves the taxonomy relationship to the term object id.
* *