Make WordPress Core

Ticket #29942: taxonomy.php.patch

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

taxonomy.php patch

  • wp-includes/taxonomy.php

     
    22802280        $taxonomies = "'" . implode("', '", $taxonomies) . "'";
    22812281        $object_ids = implode(', ', $object_ids);
    22822282
    2283         $select_this = '';
    2284         if ( 'all' == $fields )
    2285                 $select_this = 't.*, tt.*';
    2286         else if ( 'ids' == $fields )
    2287                 $select_this = 't.term_id';
    2288         else if ( 'names' == $fields )
    2289                 $select_this = 't.name';
    2290         else if ( 'slugs' == $fields )
    2291                 $select_this = 't.slug';
    2292         else if ( 'all_with_object_id' == $fields )
    2293                 $select_this = 't.*, tt.*, tr.object_id';
     2283        $query = "SELECT * FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order";
     2284       
     2285        // Attempt to use cached query
     2286        $key = md5( $query );
     2287        $last_changed = wp_cache_get( 'last_changed', 'terms' );
     2288        if ( ! $last_changed ) {
     2289                $last_changed = microtime();
     2290                wp_cache_set( 'last_changed', $last_changed, 'terms' );
     2291        }
     2292        $cache_key = "wp_get_object_terms:$key:$last_changed";
     2293        $cache = wp_cache_get( $cache_key, 'terms' );
     2294       
     2295        if ( false !== $cache ) {
     2296                $_terms = $cache;
     2297        } else {
     2298                $_terms = $wpdb->get_results( $query );
     2299                wp_cache_set( $cache_key, $_terms, 'terms', DAY_IN_SECONDS );
     2300        }
    22942301
    2295         $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order";
    2296 
    22972302        $objects = false;
    22982303        if ( 'all' == $fields || 'all_with_object_id' == $fields ) {
    2299                 $_terms = $wpdb->get_results( $query );
    23002304                foreach ( $_terms as $key => $term ) {
    23012305                        $_terms[$key] = sanitize_term( $term, $taxonomy, 'raw' );
    23022306                }
     2307               
    23032308                $terms = array_merge( $terms, $_terms );
    23042309                update_term_cache( $terms );
    23052310                $objects = true;
    23062311        } else if ( 'ids' == $fields || 'names' == $fields || 'slugs' == $fields ) {
    2307                 $_terms = $wpdb->get_col( $query );
    23082312                $_field = ( 'ids' == $fields ) ? 'term_id' : 'name';
    23092313                foreach ( $_terms as $key => $term ) {
     2314                        switch ( $fields ) {
     2315                                case 'ids' :
     2316                                        $term = $term->term_id;
     2317                                break;
     2318                               
     2319                                case 'names' :
     2320                                        $term = $term->name;
     2321                                break;
     2322                               
     2323                                case 'slugs' :
     2324                                        $term = $term->slug;
     2325                                break;
     2326                        }
     2327                       
    23102328                        $_terms[$key] = sanitize_term_field( $_field, $term, $term, $taxonomy, 'raw' );
    23112329                }
    23122330                $terms = array_merge( $terms, $_terms );
    23132331        } else if ( 'tt_ids' == $fields ) {
    2314                 $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) $orderby $order");
     2332                $query = "SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) $orderby $order";
     2333               
     2334                // Attempt to use cached query
     2335                $key = md5( $query );
     2336                $cache_key = "wp_get_object_terms:$key:$last_changed";
     2337                $cache = wp_cache_get( $cache_key, 'terms' );
     2338               
     2339                if ( false !== $cache ) {
     2340                        $terms = $cache;
     2341                } else {
     2342                        $terms = $wpdb->get_col($query);
     2343                        wp_cache_set( $cache_key, $terms, 'terms', DAY_IN_SECONDS );
     2344                }
     2345               
    23152346                foreach ( $terms as $key => $tt_id ) {
    23162347                        $terms[$key] = sanitize_term_field( 'term_taxonomy_id', $tt_id, 0, $taxonomy, 'raw' ); // 0 should be the term id, however is not needed when using raw context.
    23172348                }
     
    23342365        } elseif ( ! $objects ) {
    23352366                $terms = array_values( array_unique( $terms ) );
    23362367        }
     2368       
    23372369        /**
    23382370         * Filter the terms for a given object or objects.
    23392371         *