Make WordPress Core


Ignore:
Timestamp:
10/10/2015 01:58:37 AM (9 years ago)
Author:
boonebgorges
Message:

Introduce WP_Term.

get_term() now returns a WP_Term object, instead of a stdClass object.
Cache support and sanitization filters for individual terms are now more
centralized. For example, get_term_by() is able to cast results of its query
to a WP_Term object by passing it through get_term().

The $taxonomy parameter for get_term() is now optional, as terms ought to
be unique to a taxonomy (ie, shared terms no longer exist). In cases where
get_term() detects that the term matching the specified term_id is from the
wrong taxonomy, it checks to see if you've requested a shared term, and if so,
it splits the term. This is used only for fallback purposes.

The elimination of shared terms allows the caching strategy for terms to be
simplified. Individual terms are now cached in a single 'terms' bucket.

Props flixos90, boonebgorges, scribu, dipesh.kakadiya.
See #14162.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/getTermBy.php

    r34679 r34997  
    6060        $this->assertSame( $t, $found->term_id );
    6161    }
     62
     63    /**
     64     * @ticket 14162
     65     */
     66    public function test_should_prime_term_cache() {
     67        global $wpdb;
     68
     69        register_taxonomy( 'wptests_tax', 'post' );
     70        $t = $this->factory->term->create( array(
     71            'taxonomy' => 'wptests_tax',
     72            'slug' => 'foo',
     73        ) );
     74
     75        clean_term_cache( $t, 'wptests_tax' );
     76
     77        $num_queries = $wpdb->num_queries;
     78        $found = get_term_by( 'slug', 'foo', 'wptests_tax' );
     79        $num_queries++;
     80
     81        $this->assertTrue( $found instanceof WP_Term );
     82        $this->assertSame( $t, $found->term_id );
     83        $this->assertSame( $num_queries, $wpdb->num_queries );
     84
     85        // Calls to `get_term()` should now hit cache.
     86        $found2 = get_term( $t );
     87        $this->assertSame( $t, $found->term_id );
     88        $this->assertSame( $num_queries, $wpdb->num_queries );
     89    }
    6290}
Note: See TracChangeset for help on using the changeset viewer.