[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:07:56 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):

 I tried setting the `items` key for the `test` arg to `string` like you
 suggested above but I get something like this after that:
 [[Image(https://www.dropbox.com/s/h8sjdewr2utjrxv/Screen%20Shot%202017-12-29%20at%2011.40.52.png?dl=1)]]

 > Your debugging output is telling you exactly where to look in the code
 to see what is wrong.
 > https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-
 api.php#L1092
 I tried reading the rest api code from trac but couldn't figure out what
 the `items` keyword was used for. I also tried to google for documentation
 or blog posts where someone would have used the `array` type but came
 short.

 > Is your bug report that `items` should not be required for `array` type
 params?
 Because I couldn't find any documentation or examples related to the
 different options available for the `type` key for args and then
 encountered an error I couldn't fix I felt that opening an issue here was
 the right thing to do. At this point I'm asking the community if I'm using
 this wrong or if there's a possible bug or a chance for improvement here.

 What comes to the validation I think having a compulsory type set for the
 array values sounds like a good idea as long as it supports all current
 types, works recursively (like it does now) and its usage is documented
 somewhere.

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


More information about the wp-trac mailing list