WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#30117 closed defect (bug) (fixed)

Possible regression in taxonomy.php sanitize_query

Reported by: tmtrademark Owned by: boonebgorges
Milestone: 4.1 Priority: normal
Severity: normal Version: 4.1
Component: Taxonomy Keywords:
Focuses: Cc:

Description

I work in the VIP QuickStart environment, and on updating to the 4.1 alpha, I believe I may have experienced a regression.

The following works as expected to modify the query and return posts with the extra argument in 4.0

function rt_favorite_exclude_free_listings( $query ) {
	
	if( $query->is_main_query() && is_tax( 'favorite-category' ) && !$query->get('listings') ) {
		
		$tax_query = (array) $query->get( 'tax_query' );
		
		$tax_query[] = array(
			'taxonomy' => 'favorite-type',
			'field' => 'slug',
			'terms' => 'premium',
		);
		$query->set( 'tax_query', $tax_query );
	}
}
add_action( 'pre_get_posts', 'rt_favorite_exclude_free_listings' );

In 4.1, the following errors are thrown:

( ! ) Warning: array_merge(): Argument #2 is not an array in /srv/www/wp/wp-includes/taxonomy.php on line 757
Call Stack
#	Time	Memory	Function	Location
1	0.0062	143404	{main}( )	../index.php:0
2	0.0116	145252	require( '/srv/www/wp/wp-blog-header.php' )	../index.php:4
3	5.1287	27041896	wp( )	../wp-blog-header.php:14
4	5.1287	27041968	WP->main( )	../functions.php:873
5	5.1409	27262256	WP->query_posts( )	../class-wp.php:612
6	5.1409	27262536	WP_Query->query( )	../class-wp.php:541
7	5.1409	27264220	WP_Query->get_posts( )	../query.php:3843
8	5.1444	27311944	WP_Query->parse_tax_query( )	../query.php:2683
9	5.1446	27313696	WP_Tax_Query->__construct( )	../query.php:2026
10	5.1446	27313724	WP_Tax_Query->sanitize_query( )	../taxonomy.php:724
11	5.1446	27314672	array_merge ( )	../taxonomy.php:757

( ! ) Notice: Undefined index: field in /srv/www/wp/wp-includes/taxonomy.php on line 1152
Call Stack
#	Time	Memory	Function	Location
1	0.0062	143404	{main}( )	../index.php:0
2	0.0116	145252	require( '/srv/www/wp/wp-blog-header.php' )	../index.php:4
3	5.1287	27041896	wp( )	../wp-blog-header.php:14
4	5.1287	27041968	WP->main( )	../functions.php:873
5	5.1409	27262256	WP->query_posts( )	../class-wp.php:612
6	5.1409	27262536	WP_Query->query( )	../class-wp.php:541
7	5.1409	27264220	WP_Query->get_posts( )	../query.php:3843
8	5.1518	27313192	WP_Tax_Query->get_sql( )	../query.php:2685
9	5.1518	27313576	WP_Tax_Query->get_sql_clauses( )	../taxonomy.php:857
10	5.1518	27313892	WP_Tax_Query->get_sql_for_query( )	../taxonomy.php:882
11	5.1518	27315140	WP_Tax_Query->get_sql_for_clause( )	../taxonomy.php:933
12	5.1518	27315760	WP_Tax_Query->clean_query( )	../taxonomy.php:1001

Change History (2)

#1 @boonebgorges
5 years ago

  • Milestone changed from Awaiting Review to 4.1
  • Owner set to boonebgorges
  • Status changed from new to accepted

tmtrademark and I have worked through this at WCSF contributor day. Turns out there is a regression where WP_Tax_Query::sanitize_queries() returns a bum result if one of the items passed in the $tax_query array is an empty string - it was passing the is_first_order_clause() check, because empty( $clause ) was returning true.

#2 @boonebgorges
5 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 30031:

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.

Note: See TracTickets for help on using tickets.