Make WordPress Core


Ignore:
Timestamp:
03/11/2017 02:26:11 AM (8 years ago)
Author:
boonebgorges
Message:

Don't run 'get_terms' filter when querying for terms within get_term_by().

Historically, it has been possible to call get_term_by() within
a 'get_terms' filter callback. Since get_term_by() was refactored
to use get_terms() internally [38677], callbacks of this nature
have resulted in infinite loops.

As a workaround, we introduce a 'suppress_filter' option to get_terms(),
and use it when calling the function from within get_term_by().

Props ocean90.
See #21760.

File:
1 edited

Legend:

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

    r38677 r40275  
    193193        $this->assertContains( 'LIMIT 1', $wpdb->last_query );
    194194    }
     195
     196    /**
     197     * @ticket 21760
     198     */
     199    public function test_prevent_recursion_by_get_terms_filter() {
     200        $action = new MockAction();
     201
     202        add_filter( 'get_terms', array( $action, 'filter' ) );
     203        get_term_by( 'name', 'burrito', 'post_tag' );
     204        remove_filter( 'get_terms', array( $action, 'filter' ) );
     205
     206        $this->assertEquals( 0, $action->get_call_count() );
     207    }
    195208}
Note: See TracChangeset for help on using the changeset viewer.