Make WordPress Core

Ticket #26234: 26234.2.patch

File 26234.2.patch, 3.6 KB (added by johnjamesjacoby, 12 years ago)

Same as 26234.patch but also brings clean_object_term_cache() into the mix

  • wp-includes/category-template.php

    diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php
    index 57f7cb9..258b397 100644
    a b  
    10881088        $terms = get_object_term_cache( $post->ID, $taxonomy );
    10891089        if ( false === $terms ) {
    10901090                $terms = wp_get_object_terms( $post->ID, $taxonomy );
    1091                 wp_cache_add($post->ID, $terms, $taxonomy . '_relationships');
     1091                wp_cache_add($post->ID, $terms, _get_taxonomy_cache_key( $taxonomy ) . '_relationships');
    10921092        }
    10931093
    10941094        $terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy );
     
    11271127                $term_links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
    11281128        }
    11291129
    1130         $term_links = apply_filters( "term_links-$taxonomy", $term_links );
     1130        $taxonomy_key = _get_taxonomy_cache_key( $taxonomy );
     1131        $term_links = apply_filters( "term_links-$taxonomy_key", $term_links );
    11311132
    11321133        return $before . join( $sep, $term_links ) . $after;
    11331134}
  • wp-includes/taxonomy.php

    diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php
    index 06a9126..c3f6b4d 100644
    a b  
    23172317                                return new WP_Error( 'db_insert_error', __( 'Could not insert term relationship into the database' ), $wpdb->last_error );
    23182318        }
    23192319
    2320         wp_cache_delete( $object_id, $taxonomy . '_relationships' );
     2320        wp_cache_delete( $object_id, _get_taxonomy_cache_key( $taxonomy ) . '_relationships' );
    23212321
    23222322        do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids);
    23232323        return $tt_ids;
     
    27262726                $object_ids = array($object_ids);
    27272727
    27282728        $taxonomies = get_object_taxonomies( $object_type );
     2729        $taxonomy   = _get_taxonomy_cache_key( $taxonomies );
    27292730
    2730         foreach ( $object_ids as $id )
    2731                 foreach ( $taxonomies as $taxonomy )
    2732                         wp_cache_delete($id, "{$taxonomy}_relationships");
     2731        foreach ( $object_ids as $id ) {
     2732                wp_cache_delete( $id, "{$taxonomy}_relationships" );
     2733        }
    27332734
    27342735        do_action('clean_object_term_cache', $object_ids, $object_type);
    27352736}
     
    28082809 * @return bool|array Empty array if $terms found, but not $taxonomy. False if nothing is in cache for $taxonomy and $id.
    28092810 */
    28102811function get_object_term_cache($id, $taxonomy) {
     2812        $taxonomy = _get_taxonomy_cache_key( $taxonomy );
    28112813        $cache = wp_cache_get($id, "{$taxonomy}_relationships");
    28122814        return $cache;
    28132815}
     
    28442846        $object_ids = array_map('intval', $object_ids);
    28452847
    28462848        $taxonomies = get_object_taxonomies($object_type);
     2849        $taxonomy_key = _get_taxonomy_cache_key( $taxonomies );
    28472850
    28482851        $ids = array();
    28492852        foreach ( (array) $object_ids as $id ) {
    2850                 foreach ( $taxonomies as $taxonomy ) {
    2851                         if ( false === wp_cache_get($id, "{$taxonomy}_relationships") ) {
    2852                                 $ids[] = $id;
    2853                                 break;
    2854                         }
     2853                if ( false === wp_cache_get($id, "{$taxonomy_key}_relationships") ) {
     2854                        $ids[] = $id;
     2855                        break;
    28552856                }
    28562857        }
    28572858
     
    28652866                $object_terms[$term->object_id][$term->taxonomy][$term->term_id] = $term;
    28662867
    28672868        foreach ( $ids as $id ) {
    2868                 foreach ( $taxonomies as $taxonomy ) {
    2869                         if ( ! isset($object_terms[$id][$taxonomy]) ) {
    2870                                 if ( !isset($object_terms[$id]) )
    2871                                         $object_terms[$id] = array();
    2872                                 $object_terms[$id][$taxonomy] = array();
    2873                         }
     2869                if ( ! isset($object_terms[$id][$taxonomy_key]) ) {
     2870                        if ( !isset($object_terms[$id]) )
     2871                                $object_terms[$id] = array();
     2872                        $object_terms[$id][$taxonomy_key] = array();
    28742873                }
    28752874        }
    28762875
    28772876        foreach ( $object_terms as $id => $value ) {
    2878                 foreach ( $value as $taxonomy => $terms ) {
    2879                         wp_cache_add( $id, $terms, "{$taxonomy}_relationships" );
    2880                 }
     2877                wp_cache_add( $id, $terms, "{$taxonomy_key}_relationships" );
    28812878        }
    28822879}
    28832880