WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/10/2015 01:58:37 AM (6 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/getTerm.php

    r34035 r34997  
    3434
    3535        $this->assertSame( $num_queries, $wpdb->num_queries );
    36     }
    37 
    38     public function test_passing_term_object_should_not_skip_database_query_when_filter_property_is_set() {
    39         global $wpdb;
    40 
    41         $term = $this->factory->term->create_and_get( array( 'taxonomy' => 'wptests_tax' ) );
    42         clean_term_cache( $term->term_id, 'wptests_tax' );
    43 
    44         $num_queries = $wpdb->num_queries;
    45 
    46         $term_a = get_term( $term, 'wptests_tax' );
    47 
    48         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    4936    }
    5037
     
    9986        $this->assertInternalType( 'object', get_term( $t, 'wptests_tax', 'foo' ) );
    10087    }
     88
     89    /**
     90     * @ticket 14162
     91     */
     92    public function test_numeric_properties_should_be_cast_to_ints() {
     93        global $wpdb;
     94
     95        $t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     96
     97        // Get raw data from the database.
     98        $term_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms t JOIN $wpdb->term_taxonomy tt ON ( t.term_id = tt.term_id ) WHERE t.term_id = %d", $t ) );
     99
     100        $found = get_term( $term_data );
     101
     102        $this->assertTrue( $found instanceof WP_Term );
     103        $this->assertInternalType( 'int', $found->term_id );
     104        $this->assertInternalType( 'int', $found->term_taxonomy_id );
     105        $this->assertInternalType( 'int', $found->parent );
     106        $this->assertInternalType( 'int', $found->count );
     107        $this->assertInternalType( 'int', $found->term_group );
     108    }
    101109}
Note: See TracChangeset for help on using the changeset viewer.