diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php
index c2797b0..9d76ca7 100644
|
|
function &get_terms($taxonomies, $args = '') { |
1150 | 1150 | // $args can be whatever, only use the args defined in defaults to compute the key |
1151 | 1151 | $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : ''; |
1152 | 1152 | $key = md5( serialize( compact(array_keys($defaults)) ) . serialize( $taxonomies ) . $filter_key ); |
1153 | | $last_changed = wp_cache_get('last_changed', 'terms'); |
1154 | | if ( !$last_changed ) { |
1155 | | $last_changed = time(); |
1156 | | wp_cache_set('last_changed', $last_changed, 'terms'); |
| 1153 | $cache_key = "get_terms:$key"; |
| 1154 | |
| 1155 | // save $key so that it could be invalidated later |
| 1156 | $cache_keys = wp_cache_get( 'get_terms:cache_keys', 'terms' ); |
| 1157 | if ( ! $cache_keys ) { |
| 1158 | $cache_keys = array(); |
1157 | 1159 | } |
1158 | | $cache_key = "get_terms:$key:$last_changed"; |
| 1160 | $cache_keys[$keys] = $taxonomies; |
| 1161 | wp_cache_set( 'get_terms:cache_keys', $cache_keys, 'terms' ); |
| 1162 | |
1159 | 1163 | $cache = wp_cache_get( $cache_key, 'terms' ); |
1160 | 1164 | if ( false !== $cache ) { |
1161 | 1165 | $cache = apply_filters('get_terms', $cache, $taxonomies, $args); |
… |
… |
function &get_terms($taxonomies, $args = '') { |
1297 | 1301 | |
1298 | 1302 | if ( 'count' == $fields ) { |
1299 | 1303 | $term_count = $wpdb->get_var($query); |
| 1304 | wp_cache_add( $cache_key, $term_count, 'terms' ); |
1300 | 1305 | return $term_count; |
1301 | 1306 | } |
1302 | 1307 | |
… |
… |
function wp_delete_term( $term, $taxonomy, $args = array() ) { |
1707 | 1712 | if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) ) |
1708 | 1713 | $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->terms WHERE term_id = %d", $term) ); |
1709 | 1714 | |
1710 | | clean_term_cache($term, $taxonomy); |
| 1715 | clean_term_cache($term, $taxonomy, true, true); |
1711 | 1716 | |
1712 | 1717 | do_action('delete_term', $term, $tt_id, $taxonomy); |
1713 | 1718 | do_action("delete_$taxonomy", $term, $tt_id); |
… |
… |
function wp_insert_term( $term, $taxonomy, $args = array() ) { |
2001 | 2006 | |
2002 | 2007 | $term_id = apply_filters('term_id_filter', $term_id, $tt_id); |
2003 | 2008 | |
2004 | | clean_term_cache($term_id, $taxonomy); |
| 2009 | clean_term_cache( $term_id, $taxonomy, true, (bool) $parent ); |
2005 | 2010 | |
2006 | 2011 | do_action("created_term", $term_id, $tt_id, $taxonomy); |
2007 | 2012 | do_action("created_$taxonomy", $term_id, $tt_id); |
… |
… |
function clean_object_term_cache($object_ids, $object_type) { |
2440 | 2445 | * @param int|array $ids Single or list of Term IDs |
2441 | 2446 | * @param string $taxonomy Can be empty and will assume tt_ids, else will use for context. |
2442 | 2447 | * @param bool $clean_taxonomy Whether to clean taxonomy wide caches (true), or just individual term object caches (false). Default is true. |
| 2448 | * @param bool $force_clean_taxonomy Whether to force clean taxonomy wide caches (true), or skip if it's already done (false). Default is false |
| 2449 | * |
2443 | 2450 | */ |
2444 | | function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { |
| 2451 | function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true, $force_clean_taxonomy = false) { |
2445 | 2452 | global $wpdb; |
2446 | 2453 | static $cleaned = array(); |
2447 | 2454 | |
… |
… |
function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { |
2471 | 2478 | } |
2472 | 2479 | |
2473 | 2480 | foreach ( $taxonomies as $taxonomy ) { |
2474 | | if ( isset($cleaned[$taxonomy]) ) |
| 2481 | if ( isset($cleaned[$taxonomy]) && ! $force_clean_taxonomy ) |
2475 | 2482 | continue; |
2476 | 2483 | $cleaned[$taxonomy] = true; |
2477 | 2484 | |
2478 | 2485 | if ( $clean_taxonomy ) { |
2479 | 2486 | wp_cache_delete('all_ids', $taxonomy); |
2480 | 2487 | wp_cache_delete('get', $taxonomy); |
| 2488 | |
| 2489 | // clear get_terms cache |
| 2490 | $cache_keys = wp_cache_get( 'get_terms:cache_keys', 'terms' ); |
| 2491 | if ( ! empty( $cache_keys ) ) { |
| 2492 | foreach ( $cache_keys as $key => $cache_taxonomies ) { |
| 2493 | if ( in_array( $taxonomy, $cache_taxonomies ) ) { |
| 2494 | wp_cache_delete( "get_terms:{$key}", 'terms' ); |
| 2495 | unset( $cache_keys[$key] ); |
| 2496 | } |
| 2497 | } |
| 2498 | } else { |
| 2499 | $cache_keys = array(); |
| 2500 | } |
| 2501 | wp_cache_set( 'get_terms:cache_keys', $cache_keys, 'terms' ); |
| 2502 | |
2481 | 2503 | delete_option("{$taxonomy}_children"); |
2482 | 2504 | // Regenerate {$taxonomy}_children |
2483 | 2505 | _get_term_hierarchy($taxonomy); |
… |
… |
function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { |
2485 | 2507 | |
2486 | 2508 | do_action('clean_term_cache', $ids, $taxonomy); |
2487 | 2509 | } |
2488 | | |
2489 | | wp_cache_set('last_changed', time(), 'terms'); |
2490 | 2510 | } |
2491 | 2511 | |
2492 | 2512 | |