WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#37135 closed enhancement (wontfix)

Fluent interface for WP_REST_Response class

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

Description

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().

Why?
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.


5 years ago

#2 @joehoyle
4 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.