Improve WP_Tax_Query
param sanitization for empty strings.
When an empty string is passed as one of the clauses in the `$tax_query` parameter, it should be discarded rather than parsed as a first-order clause. Props tmtrademark. Fixes #30117. git-svn-id: https://develop.svn.wordpress.org/trunk@30031 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b92307f58d
commit
ae0ae95be6
@ -832,7 +832,7 @@ class WP_Tax_Query {
|
|||||||
* @return bool Whether the query clause is a first-order clause.
|
* @return bool Whether the query clause is a first-order clause.
|
||||||
*/
|
*/
|
||||||
protected static function is_first_order_clause( $query ) {
|
protected static function is_first_order_clause( $query ) {
|
||||||
return empty( $query ) || array_key_exists( 'terms', $query ) || array_key_exists( 'taxonomy', $query ) || array_key_exists( 'include_children', $query ) || array_key_exists( 'field', $query ) || array_key_exists( 'operator', $query );
|
return is_array( $query ) && ( empty( $query ) || array_key_exists( 'terms', $query ) || array_key_exists( 'taxonomy', $query ) || array_key_exists( 'include_children', $query ) || array_key_exists( 'field', $query ) || array_key_exists( 'operator', $query ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,6 +85,21 @@ class Tests_Tax_Query extends WP_UnitTestCase {
|
|||||||
$this->assertEquals( array( 'foo', ), $tq->queries[0]['terms'] );
|
$this->assertEquals( array( 'foo', ), $tq->queries[0]['terms'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 30117
|
||||||
|
*/
|
||||||
|
public function test_construct_empty_strings_array_members_should_be_discarded() {
|
||||||
|
$q = new WP_Tax_Query( array(
|
||||||
|
'',
|
||||||
|
array(
|
||||||
|
'taxonomy' => 'post_tag',
|
||||||
|
'terms' => 'foo',
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertSame( 1, count( $q->queries ) );
|
||||||
|
}
|
||||||
|
|
||||||
public function test_transform_query_terms_empty() {
|
public function test_transform_query_terms_empty() {
|
||||||
$tq = new WP_Tax_Query( array(
|
$tq = new WP_Tax_Query( array(
|
||||||
array(),
|
array(),
|
||||||
|
Loading…
Reference in New Issue
Block a user