mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@40275 git-svn-id: http://core.svn.wordpress.org/trunk@40192 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
afdef17903
commit
bdd898045d
@ -849,6 +849,7 @@ function get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter
|
||||
'taxonomy' => $taxonomy,
|
||||
'update_term_meta_cache' => false,
|
||||
'orderby' => 'none',
|
||||
'suppress_filter' => true,
|
||||
);
|
||||
|
||||
switch ( $field ) {
|
||||
@ -1012,6 +1013,7 @@ function get_term_to_edit( $id, $taxonomy ) {
|
||||
* a list of WP_Term objects.
|
||||
* @since 4.5.0 Changed the function signature so that the `$args` array can be provided as the first parameter.
|
||||
* Introduced 'meta_key' and 'meta_value' parameters. Introduced the ability to order results by metadata.
|
||||
* @since 4.8.0 Introduced 'suppress_filter' parameter.
|
||||
*
|
||||
* @internal The `$deprecated` parameter is parsed for backward compatibility only.
|
||||
*
|
||||
@ -1083,6 +1085,7 @@ function get_term_to_edit( $id, $taxonomy ) {
|
||||
* @type string $meta_type Type of object metadata is for (e.g., comment, post, or user).
|
||||
* Default empty.
|
||||
* @type string $meta_compare Comparison operator to test the 'meta_value'. Default empty.
|
||||
* @type bool $suppress_filter Whether to suppress the {@see 'get_terms'} filter. Default false.
|
||||
* }
|
||||
* @param array $deprecated Argument array, when using the legacy function parameter format. If present, this
|
||||
* parameter will be interpreted as `$args`, and the first function parameter will
|
||||
@ -1095,6 +1098,10 @@ function get_terms( $args = array(), $deprecated = '' ) {
|
||||
|
||||
$term_query = new WP_Term_Query();
|
||||
|
||||
$defaults = array(
|
||||
'suppress_filter' => false,
|
||||
);
|
||||
|
||||
/*
|
||||
* Legacy argument format ($taxonomy, $args) takes precedence.
|
||||
*
|
||||
@ -1108,10 +1115,10 @@ function get_terms( $args = array(), $deprecated = '' ) {
|
||||
|
||||
if ( $do_legacy_args ) {
|
||||
$taxonomies = (array) $args;
|
||||
$args = wp_parse_args( $deprecated );
|
||||
$args = wp_parse_args( $deprecated, $defaults );
|
||||
$args['taxonomy'] = $taxonomies;
|
||||
} else {
|
||||
$args = wp_parse_args( $args );
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
if ( isset( $args['taxonomy'] ) && null !== $args['taxonomy'] ) {
|
||||
$args['taxonomy'] = (array) $args['taxonomy'];
|
||||
}
|
||||
@ -1125,6 +1132,10 @@ function get_terms( $args = array(), $deprecated = '' ) {
|
||||
}
|
||||
}
|
||||
|
||||
// Don't pass suppress_filter to WP_Term_Query.
|
||||
$suppress_filter = $args['suppress_filter'];
|
||||
unset( $args['suppress_filter'] );
|
||||
|
||||
$terms = $term_query->query( $args );
|
||||
|
||||
// Count queries are not filtered, for legacy reasons.
|
||||
@ -1132,6 +1143,10 @@ function get_terms( $args = array(), $deprecated = '' ) {
|
||||
return $terms;
|
||||
}
|
||||
|
||||
if ( $suppress_filter ) {
|
||||
return $terms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the found terms.
|
||||
*
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.8-alpha-40271';
|
||||
$wp_version = '4.8-alpha-40275';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user