Cleanup clean_term_cache(). Props Denis-de-Bernardy. see #11530

git-svn-id: http://svn.automattic.com/wordpress/trunk@12510 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-12-23 14:37:21 +00:00
parent e7d9a6913a
commit 36d9a3677e
1 changed files with 10 additions and 6 deletions

View File

@ -1860,18 +1860,23 @@ function clean_term_cache($ids, $taxonomy = '') {
$taxonomies = array(); $taxonomies = array();
// If no taxonomy, assume tt_ids. // If no taxonomy, assume tt_ids.
if ( empty($taxonomy) ) { if ( empty($taxonomy) ) {
$tt_ids = implode(', ', $ids); $tt_ids = array_map('intval', $ids);
$tt_ids = implode(', ', $tt_ids);
$terms = $wpdb->get_results("SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)"); $terms = $wpdb->get_results("SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)");
$ids = array();
foreach ( (array) $terms as $term ) { foreach ( (array) $terms as $term ) {
$taxonomies[] = $term->taxonomy; $taxonomies[] = $term->taxonomy;
$ids[] = $term->term_id;
wp_cache_delete($term->term_id, $term->taxonomy); wp_cache_delete($term->term_id, $term->taxonomy);
} }
$taxonomies = array_unique($taxonomies); $taxonomies = array_unique($taxonomies);
} else { } else {
foreach ( $ids as $id ) {
wp_cache_delete($id, $taxonomy);
}
$taxonomies = array($taxonomy); $taxonomies = array($taxonomy);
foreach ( $taxonomies as $taxonomy ) {
foreach ( $ids as $id ) {
wp_cache_delete($id, $taxonomy);
}
}
} }
foreach ( $taxonomies as $taxonomy ) { foreach ( $taxonomies as $taxonomy ) {
@ -1881,11 +1886,10 @@ function clean_term_cache($ids, $taxonomy = '') {
wp_cache_delete('all_ids', $taxonomy); wp_cache_delete('all_ids', $taxonomy);
wp_cache_delete('get', $taxonomy); wp_cache_delete('get', $taxonomy);
delete_option("{$taxonomy}_children"); delete_option("{$taxonomy}_children");
do_action('clean_term_cache', $ids, $taxonomy);
} }
wp_cache_set('last_changed', time(), 'terms'); wp_cache_set('last_changed', time(), 'terms');
do_action('clean_term_cache', $ids, $taxonomy);
} }