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