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. Built from https://develop.svn.wordpress.org/trunk@45584 git-svn-id: http://core.svn.wordpress.org/trunk@45395 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
cf3fa9f7c8
commit
4568c13df8
|
@ -672,6 +672,26 @@ class WP_Term_Query {
|
||||||
|
|
||||||
$this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
|
$this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
|
||||||
|
|
||||||
|
$this->terms = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter the terms array before the query takes place.
|
||||||
|
*
|
||||||
|
* Return a non-null value to bypass WordPress's default term queries.
|
||||||
|
*
|
||||||
|
* @since 5.3.0
|
||||||
|
*
|
||||||
|
* @param array|null $terms Return an array of term data to short-circuit WP's term query,
|
||||||
|
* or null to allow WP queries to run normally.
|
||||||
|
* @param WP_Term_Query $this The WP_Term_Query instance, passed by reference.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$this->terms = apply_filters_ref_array( 'terms_pre_query', array( $this->terms, &$this ) );
|
||||||
|
|
||||||
|
if ( null !== $this->terms ) {
|
||||||
|
return $this->terms;
|
||||||
|
}
|
||||||
|
|
||||||
// $args can be anything. Only use the args defined in defaults to compute the key.
|
// $args can be anything. Only use the args defined in defaults to compute the key.
|
||||||
$key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request );
|
$key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request );
|
||||||
$last_changed = wp_cache_get_last_changed( 'terms' );
|
$last_changed = wp_cache_get_last_changed( 'terms' );
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.3-alpha-45583';
|
$wp_version = '5.3-alpha-45584';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue