Make WordPress Core

Opened 10 years ago

Last modified 8 years ago

#39851 new task (blessed)

WP_REST_Posts_Controller::get_items() has too many concerns

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

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.

Attachments (1)

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

Download all attachments as: .zip

Change History (5)

@Shelob9
10 years ago

Initial pass at abstracting response preparation from get_items() method

#1 @rmccue
10 years ago

  • Type defect (bug) → task (blessed)

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

#2 @joehoyle
10 years ago

+1 from me also

#3 @Shelob9
10 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
8 years ago

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