Make WordPress Core

Opened 7 years ago

Last modified 5 years ago

#39851 new task (blessed)

WP_REST_Posts_Controller::get_items() has too many concerns

Reported by: shelob9's profile Shelob9 Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords:
Focuses: Cc:


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.

Attachments (1)

39851.diff (6.2 KB) - added by Shelob9 7 years ago.
Initial pass at abstracting response preparation from get_items() method

Download all attachments as: .zip

Change History (5)

7 years ago

Initial pass at abstracting response preparation from get_items() method

#1 @rmccue
7 years ago

  • Type changed from defect (bug) to task (blessed)

Let's refactor this and split it up into multiple methods. :)

#2 @joehoyle
7 years ago

+1 from me also

#3 @Shelob9
7 years ago

I'm thinking, as an alternative to my ticket, what about a WP_REST_Post_Query class that took an array of WP_Query ARGS and generated a proper response?

#4 @desrosj
5 years ago

  • Milestone changed from Awaiting Review to Future Release
Note: See TracTickets for help on using tickets.