Make WordPress Core


Ignore:
Timestamp:
07/01/2019 08:47:21 PM (6 years ago)
Author:
adamsilverstein
Message:

Taxonomy: add a new 'terms_pre_query' filter to short circuit WP_Term_Query 'get_terms' queries.

Add a new terms_pre_query filter which returns null by default. Return a non-null value to bypass WordPress's default get_terms queries.

Props jarocks, boonebgorges, spacedmonkey.
Fixes #41246.

File:
1 edited

Legend:

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

    r43571 r45584  
    673673        $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
    674674
     675        $this->terms = null;
     676
     677        /**
     678         * Filter the terms array before the query takes place.
     679         *
     680         * Return a non-null value to bypass WordPress's default term queries.
     681         *
     682         * @since 5.3.0
     683         *
     684         * @param array|null    $terms Return an array of term data to short-circuit WP's term query,
     685         *                             or null to allow WP queries to run normally.
     686         * @param WP_Term_Query $this  The WP_Term_Query instance, passed by reference.
     687         *
     688         */
     689        $this->terms = apply_filters_ref_array( 'terms_pre_query', array( $this->terms, &$this ) );
     690
     691        if ( null !== $this->terms ) {
     692            return $this->terms;
     693        }
     694
    675695        // $args can be anything. Only use the args defined in defaults to compute the key.
    676696        $key          = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request );
Note: See TracChangeset for help on using the changeset viewer.