Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#37135 closed enhancement (wontfix)

Fluent interface for WP_REST_Response class

Reported by: tfrommen's profile tfrommen Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: REST API Keywords:
Focuses: Cc:


Hi there,

it would be really handy to give (at least) the WP_REST_Response class a fluent interface. This is as easy as return $this (as well as adapting the according PHPDoc annotation) in the following methods:

  • WP_REST_Response::add_link();
  • WP_REST_Response::add_links();
  • WP_REST_Response::link_header();
  • WP_REST_Response::set_matched_handler();
  • WP_REST_Response::set_matched_route().

So one can do this:

return ( new WP_REST_Response() )->set_matched_route( /* */ )->add_links( /* */ );

Happy to provide the according patch, if there's an interest in that.

Change History (2)

This ticket was mentioned in Slack in #core by binarykitten. View the logs.

8 years ago

#2 @joehoyle
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Given that we don't use fluent interfaces anywhere in WordPress, I don't think it's a good idea to have it here. I'm goign to close this out as #wontfix, but feel free to comment if any strongly objects.

Note: See TracTickets for help on using tickets.