[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 18:00:24 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 | Resolution:
Keywords: | Focuses: rest-api
--------------------------+------------------------------
Comment (by rachelbaker):
@sarukuku what happens if you set the `items` key for the `test` arg? It
looks like you haven't set what type of values expect from the array.
{{{#!php
<?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',
'items' => 'string'
)
)
)
));
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42989#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list