Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#38401 closed defect (bug) (invalid)

PHP warning by WP_REST_Posts_Controller::prepare_items_query(): array_flip() can only flip string and integer values

Reported by: ocean90's profile ocean90 Owned by: coffee2code's profile coffee2code
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: close
Focuses: Cc:

Description

Noticed this on w.org with the Handbook plugin which uses a boolean value for a query var, see https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php?rev=4036&marks=329,344#L322.

Warning: array_flip(): Can only flip STRING and INTEGER values! in /wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line 704
Call Stack
#	Time	Memory	Function	Location
1	0.0001	257800	{main}( )	.../index.php:0
2	0.0002	263432	require( '/wp-blog-header.php' )	.../index.php:26
3	0.4333	8246568	wp( )	.../wp-blog-header.php:16
4	0.4333	8246784	WP->main( )	.../functions.php:955
5	0.4334	8247392	WP->parse_request( )	.../class-wp.php:725
6	0.4350	8300424	do_action_ref_array( )	.../class-wp.php:386
7	0.4350	8300648	WP_Hook->do_action( )	.../plugin.php:515
8	0.4350	8300744	WP_Hook->apply_filters( )	.../class-wp-hook.php:323
9	0.4350	8301896	call_user_func_array:{/wp-includes/class-wp-hook.php:298} ( )	.../class-wp-hook.php:298
10	0.4350	8302360	rest_api_loaded( )	.../class-wp-hook.php:298
11	0.5132	9021664	WP_REST_Server->serve_request( )	.../rest-api.php:259
12	0.5181	8926968	WP_REST_Server->dispatch( )	.../class-wp-rest-server.php:326
13	0.5247	9094800	call_user_func:{/wp-includes/rest-api/class-wp-rest-server.php:928} ( )	.../class-wp-rest-server.php:928
14	0.5247	9095336	WP_REST_Posts_Controller->get_items( )	.../class-wp-rest-server.php:928
15	0.5293	9122160	WP_REST_Posts_Controller->prepare_items_query( )	.../class-wp-rest-posts-controller.php:211
16	0.5298	9130208	array_flip ( )	.../class-wp-rest-posts-controller.php:704

Change History (4)

#1 @flixos90
8 years ago

Isn't that incorrect usage of the filter there (in the Handbook plugin)? I thought you should only add names of public query vars using the query_vars filter.

#2 @kovshenin
8 years ago

  • Keywords close added; needs-patch removed

query_vars is an array where each value is a query var and keys are not relevant. The way the handbook plugin whitelists a query var looks wrong, it should be:

$public_query_vars[] = 'is_handbook_root';

I also don't see why the query var should be public in that particular case, I don't see any custom rewrite rules using it, so it looks like a completely internal query var to me, but I may be missing something.

#3 @ocean90
8 years ago

  • Owner set to coffee2code
  • Status changed from new to reviewing

@coffee2code Can you take a look at this please?

#4 @coffee2code
8 years ago

  • Milestone 4.7 deleted
  • Resolution set to invalid
  • Status changed from reviewing to closed

Seems it was an ill-advised approach that happened to work for its intended (if unsupported) purpose until recently. I'm about to commit the change to the handbook plugin to something more conventional. As far as core is concerned this issue can be considered invalid.

I scanned the plugin directory and didn't find anyone else making use of such an approach so it doesn't seem like it'll affect many people, if any.

Note: See TracTickets for help on using tickets.