Make WordPress Core


Ignore:
Timestamp:
03/11/2022 11:05:02 AM (3 years ago)
Author:
spacedmonkey
Message:

Taxonomy: Use get_terms instead of a database lookup in term_exists().

Replace raw SQL queries to the terms table, with a call to the get_terms function. Using get_terms means that term_exists is now cached. For developers using term_exists where cache invalidation is disabled, such as importing, a workaround was added to ensure that queries are uncached.

Props Spacedmonkey, boonebgorges, flixos90, peterwilsoncc.
Fixes #36949.

File:
1 edited

Legend:

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

    r52389 r52921  
    5555            array( '%d' )
    5656        );
     57        clean_term_cache( $t1['term_id'], 'category' );
    5758
    5859        $t2_child = wp_insert_term(
     
    152153            array( '%d' )
    153154        );
     155        clean_term_cache( $t1['term_id'], 'category' );
    154156        $th = _get_term_hierarchy( 'wptests_tax_4' );
    155157
     
    180182            array( '%d' )
    181183        );
     184        clean_term_cache( $t1['term_id'], 'category' );
    182185
    183186        $this->assertSame( $t1['term_id'], get_option( 'default_category', -1 ) );
     
    208211            array( '%d' )
    209212        );
     213        clean_term_cache( $t1['term_id'], 'category' );
    210214
    211215        $menu_id       = wp_create_nav_menu( 'Nav Menu Bar' );
     
    246250            array( 'term_taxonomy_id' => $nav_term->term_taxonomy_id )
    247251        );
     252        clean_term_cache( $shared_term_id, 'category' );
    248253
    249254        set_theme_mod( 'nav_menu_locations', array( 'foo' => $shared_term_id ) );
     
    275280            array( 'term_taxonomy_id' => $nav_term->term_taxonomy_id )
    276281        );
     282        clean_term_cache( $shared_term_id, 'category' );
    277283
    278284        $t1            = wp_insert_term( 'Random term', 'category' );
Note: See TracChangeset for help on using the changeset viewer.