[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
Fri Dec 29 10:16:29 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 sarukuku):
It seems that the `items` needs to be an array that has the key `type` in
it. The example below works as I'd expect and It's also much more
readable.
{{{#!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' => [
'type' => 'string'
]
)
)
)
));
}}}
But as we see here it's quite hard to figure these out without any
documentation. This issue as it is can (probably?) be closed now but how
should we go with improving the documentation on this? Should I open a new
issue to somewhere else?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42989#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list