Skip to content

Commit ff48c03

Browse files
author
boonebgorges
committed
Ensure that get_terms() can accept querystring-style arguments.
Prior to [37572], arguments passed to `get_terms()` were passed immediately through `wp_parse_args()`, which made it possible to pass arguments as a querystring (`hide_empty=0`) rather than an array (`array( 'hide_empty' => false )`). [37572] moved default argument parsing into `WP_Term_Query`, while assuming that arguments passed to `get_terms()` would be formatted as an array. To provide compatibility, we now parse all args passed to `get_terms()` into an array before processing. See #35381. git-svn-id: https://develop.svn.wordpress.org/trunk@37599 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9391670 commit ff48c03

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/wp-includes/taxonomy.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,15 +1183,19 @@ function get_terms( $args = array(), $deprecated = '' ) {
11831183
* (a) a second non-empty parameter is passed, or
11841184
* (b) the first parameter shares no keys with the default array (ie, it's a list of taxonomies)
11851185
*/
1186-
$key_intersect = array_intersect_key( $term_query->query_var_defaults, (array) $args );
1186+
$_args = wp_parse_args( $args );
1187+
$key_intersect = array_intersect_key( $term_query->query_var_defaults, (array) $_args );
11871188
$do_legacy_args = $deprecated || empty( $key_intersect );
11881189

11891190
if ( $do_legacy_args ) {
11901191
$taxonomies = (array) $args;
1191-
$args = $deprecated;
1192+
$args = wp_parse_args( $deprecated );
11921193
$args['taxonomy'] = $taxonomies;
1193-
} elseif ( isset( $args['taxonomy'] ) && null !== $args['taxonomy'] ) {
1194-
$args['taxonomy'] = (array) $args['taxonomy'];
1194+
} else {
1195+
$args = wp_parse_args( $args );
1196+
if ( isset( $args['taxonomy'] ) && null !== $args['taxonomy'] ) {
1197+
$args['taxonomy'] = (array) $args['taxonomy'];
1198+
}
11951199
}
11961200

11971201
$empty_array = array();

tests/phpunit/tests/term/getTerms.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@ public function test_should_accept_an_args_array_containing_taxonomy_for_first_p
2828
$this->assertEqualSets( array( $term ), $found );
2929
}
3030

31+
/**
32+
* @ticket 35495
33+
* @ticket 35381
34+
*/
35+
public function test_legacy_params_as_query_string_should_be_properly_parsed() {
36+
register_taxonomy( 'wptests_tax', 'post' );
37+
$term = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
38+
39+
$found = get_terms( 'wptests_tax', 'hide_empty=0&fields=ids&update_term_meta_cache=0' );
40+
41+
$this->assertEqualSets( array( $term ), $found );
42+
}
43+
44+
/**
45+
* @ticket 35495
46+
* @ticket 35381
47+
*/
48+
public function test_new_params_as_query_string_should_be_properly_parsed() {
49+
register_taxonomy( 'wptests_tax', 'post' );
50+
$term = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
51+
52+
$found = get_terms( 'taxonomy=wptests_tax&hide_empty=0&fields=ids&update_term_meta_cache=0' );
53+
54+
$this->assertEqualSets( array( $term ), $found );
55+
}
56+
3157
/**
3258
* @ticket 35495
3359
*/

0 commit comments

Comments
 (0)