Opened 10 years ago
Closed 10 years ago
#37135 closed enhancement (wontfix)
Fluent interface for WP_REST_Response class
| Reported by: | tfrommen | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | REST API | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.