[wp-trac] [WordPress Trac] #39376: Pass WP_REST_Request object to registered callback for a route schema.

WordPress Trac noreply at wordpress.org
Tue Jan 3 03:30:47 UTC 2017


#39376: Pass WP_REST_Request object to registered callback for a route schema.
-------------------------+----------------------
 Reporter:  nerrad       |       Owner:  jnylen0
     Type:  enhancement  |      Status:  closed
 Priority:  normal       |   Milestone:
Component:  REST API     |     Version:  4.7
 Severity:  normal       |  Resolution:  wontfix
 Keywords:               |     Focuses:
-------------------------+----------------------
Changes (by jnylen0):

 * status:  accepted => closed
 * resolution:   => wontfix
 * milestone:  4.7.1 =>


Comment:

 After giving this some more thought I'd rather fix this issue by revising
 the documentation rather than adding another parameter in the code.  The
 schema callback shouldn't care what the route is or about the details of
 the request, because the schema is the description of a single item
 regardless of what you are doing to that item.

 More generally, I would also recommend one `register_rest_route` call per
 endpoint, preferring explicit code over implicit dynamic registration.
 This makes it easier to follow what endpoints are registered, and where
 and how.  This isn't always possible though - @nerrad and I chatted some
 in DMs where he shared his code that led to this request:

 - [https://github.com/eventespresso/event-espresso-
 core/blob/ca9e8ea/modules/core_rest_api/EED_Core_Rest_Api.module.php#L77
 `rest_api_init` callback]
 - [https://github.com/eventespresso/event-espresso-
 core/blob/ca9e8ea/modules/core_rest_api/EED_Core_Rest_Api.module.php#L178
 `register_rest_route` call]
 - [https://github.com/eventespresso/event-espresso-
 core/blob/ca9e8ea/modules/core_rest_api/EED_Core_Rest_Api.module.php#L390
 `schema_callback` argument]
 - [https://github.com/eventespresso/event-espresso-
 core/blob/ca9e8ea/core/libraries/rest_api/controllers/model/Read.php#L92
 schema callback code]
 - [https://github.com/eventespresso/event-espresso-
 core/blob/ca9e8ea/core/libraries/rest_api/controllers/model/Read.php#L129
 current code to determine the request route]

 As an alternative solution, I suggested something like `schema_callback =>
 create_schema_callback( 'some_model_type' )` which seems like a better
 level of abstraction than relying on the REST route.

 I've fixed the incorrect documentation linked in the original report, so
 we can close this ticket.

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


More information about the wp-trac mailing list