[wp-trac] [WordPress Trac] #42989: REST API: Using array type when defining fields in register_rest_route() causes undefined index notices

WordPress Trac noreply at wordpress.org
Thu Dec 28 11:07:32 UTC 2017


#42989: REST API: Using array type when defining fields in register_rest_route()
causes undefined index notices
--------------------------+-----------------------------
 Reporter:  sarukuku      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.9.1
 Severity:  normal        |   Keywords:
  Focuses:  rest-api      |
--------------------------+-----------------------------
 I have error reporting turned on in dev. Then I register a route like
 this:
 {{{#!php
 register_rest_route( 'test/v1', 'array_test', array(
   array(
     'methods' => WP_REST_Server::READABLE,
     'callback' => function ( WP_REST_Request $request ) {
       // Just reflect back the value of the test parameter
       return rest_ensure_response( $request->get_param( 'test' ) );
     },
     'args' => array(
       'test' => array(
         'type' => 'array'
       )
     )
   )
 ));
 }}}

 Then I call it like this:
 {{{
 <your-dev-domain>/wp-json/test/v1/array_test/?test[]=value1&test[]=value2
 }}}

 I expect to get back a JSON response where the content looks like this:
 ["value1","value2"]. Instead I get Notice: Undefined index: items in
 /var/www/html/wp-includes/rest-api.php on line 1092 twice and then
 Warning: Cannot modify header information - headers already sent by
 (output started at /var/www/html/wp-includes/rest-api.php:1092) in
 /var/www/html/wp-includes/rest-api/class-wp-rest-server.php on line 1248.

 [[Image(https://www.dropbox.com/s/2ftpv08md3eofsw/Screen%20Shot%202017-12-28%20at%2013.02.00.png?dl=1)]]

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42989>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list