Make WordPress Core

Changeset 40979


Ignore:
Timestamp:
07/01/2017 11:45:09 AM (7 years ago)
Author:
boonebgorges
Message:

Taxonomy: Ignore cached term value when it doesn't match the queried taxonomy.

When a cache entry is found that matches the requested $term_id, but
doesn't match an explicitly provided $taxonomy, that cache entry
should be ignored.

Props GunGeekATX.
Fixes #40671.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-term.php

    r40973 r40979  
    137137        // If there isn't a cached version, hit the database.
    138138        if ( ! $_term || ( $taxonomy && $taxonomy !== $_term->taxonomy ) ) {
     139            // Any term found in the cache is not a match, so don't use it.
     140            $_term = false;
     141
    139142            // Grab all matching terms, in case any are shared between taxonomies.
    140143            $terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id = %d", $term_id ) );
  • trunk/tests/phpunit/tests/term/wpTerm.php

    r39992 r40979  
    6969        $this->assertSame( 1, $found->term_id );
    7070    }
     71
     72    /**
     73     * @ticket 40671
     74     */
     75    public function test_get_instance_should_respect_taxonomy_when_term_id_is_found_in_cache() {
     76        global $wpdb;
     77
     78        register_taxonomy( 'wptests_tax2', 'post' );
     79
     80        // Ensure that cache is primed.
     81        WP_Term::get_instance( self::$term_id, 'wptests_tax' );
     82
     83        $found = WP_Term::get_instance( self::$term_id, 'wptests_tax2' );
     84        $this->assertFalse( $found );
     85    }
    7186}
Note: See TracChangeset for help on using the changeset viewer.