Make WordPress Core

Ticket #21760: 21760.10.patch

File 21760.10.patch, 3.2 KB (added by ocean90, 7 years ago)
  • src/wp-includes/taxonomy.php

     
    849849                'taxonomy'               => $taxonomy,
    850850                'update_term_meta_cache' => false,
    851851                'orderby'                => 'none',
     852                'suppress_filter'        => true,
    852853        );
    853854
    854855        switch ( $field ) {
     
    10121013 *              a list of WP_Term objects.
    10131014 * @since 4.5.0 Changed the function signature so that the `$args` array can be provided as the first parameter.
    10141015 *              Introduced 'meta_key' and 'meta_value' parameters. Introduced the ability to order results by metadata.
     1016 * @since 4.8.0 Introduced 'suppress_filter' parameter.
    10151017 *
    10161018 * @internal The `$deprecated` parameter is parsed for backward compatibility only.
    10171019 *
     
    10801082 *                                                conjunction with `$meta_value`.
    10811083 *     @type string       $meta_value             Limit terms to those matching a specific metadata value. Usually used
    10821084 *                                                in conjunction with `$meta_key`.
     1085 *     @type bool         $suppress_filter        Whether to suppress the {@see 'get_terms'} filter. Default false.
    10831086 * }
    10841087 * @param array $deprecated Argument array, when using the legacy function parameter format. If present, this
    10851088 *                          parameter will be interpreted as `$args`, and the first function parameter will
     
    10921095
    10931096        $term_query = new WP_Term_Query();
    10941097
     1098        $defaults = array(
     1099                'suppress_filter' => false,
     1100        );
     1101
    10951102        /*
    10961103         * Legacy argument format ($taxonomy, $args) takes precedence.
    10971104         *
     
    11051112
    11061113        if ( $do_legacy_args ) {
    11071114                $taxonomies = (array) $args;
    1108                 $args = wp_parse_args( $deprecated );
     1115                $args = wp_parse_args( $deprecated, $defaults );
    11091116                $args['taxonomy'] = $taxonomies;
    11101117        } else {
    1111                 $args = wp_parse_args( $args );
     1118                $args = wp_parse_args( $args, $defaults );
    11121119                if ( isset( $args['taxonomy'] ) && null !== $args['taxonomy'] ) {
    11131120                        $args['taxonomy'] = (array) $args['taxonomy'];
    11141121                }
     
    11221129                }
    11231130        }
    11241131
     1132        // Don't pass suppress_filter to WP_Term_Query.
     1133        $suppress_filter = $args['suppress_filter'];
     1134        unset( $args['suppress_filter'] );
     1135
    11251136        $terms = $term_query->query( $args );
    11261137
    11271138        // Count queries are not filtered, for legacy reasons.
     
    11291140                return $terms;
    11301141        }
    11311142
     1143        if ( $suppress_filter ) {
     1144                return $terms;
     1145        }
     1146
    11321147        /**
    11331148         * Filters the found terms.
    11341149         *
  • tests/phpunit/tests/term/getTermBy.php

     
    192192                $this->assertSame( $term_id, $found->term_id );
    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}