Opened 8 years ago
Last modified 6 years ago
#39851 new task (blessed)
WP_REST_Posts_Controller::get_items() has too many concerns
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | |
Focuses: | Cc: |
Description
I've written a bunch of custom endpoints that return collections of posts of one or more post types. I'd like my responses to be the same formatting, body and header as the default post routes provide. This allows for a client designed to consume default routes to be more easily modified to use custom routes.
Achieving this with a subclass of WP_REST_Posts_Controller still requires some cut and paste for collections of posts, since the get_items() method has way too many concerns. I'd like to break out the preparing of response body, as well as response header into separate methods, so that they can be used with different types of requests or ways to create arrays of WP_Post objects, while still providing a consistent response.
Initial pass at abstracting response preparation from get_items() method