Make WordPress Core

Ticket #29894: taxonomy.php.patch

File taxonomy.php.patch, 2.4 KB (added by webgeekconsulting, 10 years ago)

taxonomy.php patch

  • taxonomy.php

     
    13261326                }
    13271327        }
    13281328
     1329        // $args can be whatever, only use the args defined in defaults to compute the key
     1330        $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : '';
     1331        $key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $defaults ) ) ) . serialize( $taxonomies ) . $filter_key );
     1332        $last_changed = wp_cache_get( 'last_changed', 'terms' );
     1333        if ( ! $last_changed ) {
     1334                $last_changed = microtime();
     1335                wp_cache_set( 'last_changed', $last_changed, 'terms' );
     1336        }
     1337        $cache_key = "get_terms:$key:$last_changed";
     1338        $cache = wp_cache_get( $cache_key, 'terms' );
     1339        if ( false !== $cache ) {
     1340
     1341                /**
     1342                 * Filter the given taxonomy's terms cache.
     1343                 *
     1344                 * @since 2.3.0
     1345                 *
     1346                 * @param array        $cache      Cached array of terms for the given taxonomy.
     1347                 * @param string|array $taxonomies A taxonomy or array of taxonomies.
     1348                 * @param array        $args       An array of arguments to get terms.
     1349                 */
     1350                $cache = apply_filters( 'get_terms', $cache, $taxonomies, $args );
     1351                return $cache;
     1352        }
     1353
    13291354        $_orderby = strtolower( $args['orderby'] );
    13301355        if ( 'count' == $_orderby ) {
    13311356                $orderby = 'tt.count';
     
    15301555
    15311556        $query = "SELECT $fields FROM $wpdb->terms AS t $join WHERE $where $orderby $order $limits";
    15321557
    1533         // $args can be whatever, only use the args defined in defaults to compute the key
    1534         $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : '';
    1535         $key = md5( $query . $filter_key );
    1536         $last_changed = wp_cache_get( 'last_changed', 'terms' );
    1537         if ( ! $last_changed ) {
    1538                 $last_changed = microtime();
    1539                 wp_cache_set( 'last_changed', $last_changed, 'terms' );
    1540         }
    1541         $cache_key = "get_terms:$key:$last_changed";
    1542         $cache = wp_cache_get( $cache_key, 'terms' );
    1543         if ( false !== $cache ) {
    1544 
    1545                 /**
    1546                  * Filter the given taxonomy's terms cache.
    1547                  *
    1548                  * @since 2.3.0
    1549                  *
    1550                  * @param array        $cache      Cached array of terms for the given taxonomy.
    1551                  * @param string|array $taxonomies A taxonomy or array of taxonomies.
    1552                  * @param array        $args       An array of arguments to get terms.
    1553                  */
    1554                 $cache = apply_filters( 'get_terms', $cache, $taxonomies, $args );
    1555                 return $cache;
    1556         }
    1557 
    15581558        if ( 'count' == $_fields ) {
    15591559                $term_count = $wpdb->get_var($query);
    15601560                return $term_count;