Make WordPress Core

Changeset 37623


Ignore:
Timestamp:
06/02/2016 02:37:55 PM (8 years ago)
Author:
boonebgorges
Message:

Taxonomy: Don't pass results of 'count' query through 'get_terms' filter.

Use of the 'get_terms' filter was consolidated in [37572], with the
introduction of WP_Term_Query. At that time, the result of 'count=true'
queries began being filtered by 'get_terms'. This breaks existing 'get_terms'
callbacks, which often assume that the returned value will be an array or a
WP_Error object.

Props JustinSainton.
Fixes #36992.

Location:
trunk
Files:
2 edited

Legend:

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

    r37622 r37623  
    12091209    $terms = $term_query->query( $args );
    12101210
     1211    // Count queries are not filtered, for legacy reasons.
     1212    if ( $term_query->query_vars['count'] ) {
     1213        return $terms;
     1214    }
     1215
    12111216    /**
    12121217     * Filters the found terms.
  • trunk/tests/phpunit/tests/term/getTerms.php

    r37599 r37623  
    21802180    }
    21812181
     2182    /**
     2183     * @ticket 36992
     2184     * @ticket 35381
     2185     */
     2186    public function test_count_should_pass_through_main_get_terms_filter() {
     2187        add_filter( 'get_terms', array( __CLASS__, 'maybe_filter_count' ) );
     2188
     2189        $found = get_terms( array(
     2190            'hide_empty' => 0,
     2191            'count' => true,
     2192        ) );
     2193
     2194        remove_filter( 'get_terms', array( __CLASS__, 'maybe_filter_count' ) );
     2195
     2196        $this->assertNotEquals( 'foo', $found );
     2197    }
     2198
     2199    public static function maybe_filter_count() {
     2200        return 'foo';
     2201    }
     2202
    21822203    protected function create_hierarchical_terms_and_posts() {
    21832204        $terms = array();
Note: See TracChangeset for help on using the changeset viewer.