Make WordPress Core

Ticket #14485: garyc40-14485-rev7.patch

File garyc40-14485-rev7.patch, 4.1 KB (added by garyc40, 14 years ago)

removed unnecessary isset check

  • wp-includes/taxonomy.php

    diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php
    index c2797b0..9d76ca7 100644
    function &get_terms($taxonomies, $args = '') { 
    11501150        // $args can be whatever, only use the args defined in defaults to compute the key
    11511151        $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : '';
    11521152        $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();
    11571159        }
    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
    11591163        $cache = wp_cache_get( $cache_key, 'terms' );
    11601164        if ( false !== $cache ) {
    11611165                $cache = apply_filters('get_terms', $cache, $taxonomies, $args);
    function &get_terms($taxonomies, $args = '') { 
    12971301
    12981302        if ( 'count' == $fields ) {
    12991303                $term_count = $wpdb->get_var($query);
     1304                wp_cache_add( $cache_key, $term_count, 'terms' );
    13001305                return $term_count;
    13011306        }
    13021307
    function wp_delete_term( $term, $taxonomy, $args = array() ) { 
    17071712        if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) )
    17081713                $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->terms WHERE term_id = %d", $term) );
    17091714
    1710         clean_term_cache($term, $taxonomy);
     1715        clean_term_cache($term, $taxonomy, true, true);
    17111716
    17121717        do_action('delete_term', $term, $tt_id, $taxonomy);
    17131718        do_action("delete_$taxonomy", $term, $tt_id);
    function wp_insert_term( $term, $taxonomy, $args = array() ) { 
    20012006
    20022007        $term_id = apply_filters('term_id_filter', $term_id, $tt_id);
    20032008
    2004         clean_term_cache($term_id, $taxonomy);
     2009        clean_term_cache( $term_id, $taxonomy, true, (bool) $parent );
    20052010
    20062011        do_action("created_term", $term_id, $tt_id, $taxonomy);
    20072012        do_action("created_$taxonomy", $term_id, $tt_id);
    function clean_object_term_cache($object_ids, $object_type) { 
    24402445 * @param int|array $ids Single or list of Term IDs
    24412446 * @param string $taxonomy Can be empty and will assume tt_ids, else will use for context.
    24422447 * @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 *
    24432450 */
    2444 function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
     2451function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true, $force_clean_taxonomy = false) {
    24452452        global $wpdb;
    24462453        static $cleaned = array();
    24472454
    function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { 
    24712478        }
    24722479
    24732480        foreach ( $taxonomies as $taxonomy ) {
    2474                 if ( isset($cleaned[$taxonomy]) )
     2481                if ( isset($cleaned[$taxonomy]) && ! $force_clean_taxonomy )
    24752482                        continue;
    24762483                $cleaned[$taxonomy] = true;
    24772484
    24782485                if ( $clean_taxonomy ) {
    24792486                        wp_cache_delete('all_ids', $taxonomy);
    24802487                        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                       
    24812503                        delete_option("{$taxonomy}_children");
    24822504                        // Regenerate {$taxonomy}_children
    24832505                        _get_term_hierarchy($taxonomy);
    function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { 
    24852507
    24862508                do_action('clean_term_cache', $ids, $taxonomy);
    24872509        }
    2488 
    2489         wp_cache_set('last_changed', time(), 'terms');
    24902510}
    24912511
    24922512