Opened 8 years ago
Closed 4 years ago
#39727 closed enhancement (wontfix)
REST API: Add $last_request property to WP_REST_Server as per Spy_REST_Server.
Reported by: | rheinardkorf | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7.2 |
Component: | REST API | Keywords: | close |
Focuses: | rest-api | Cc: |
Description
There are a number of times that $_GET is required to retrieve parameters. Within WP_REST_Server::serve_request()
the following code sets up a request object:
$request = new WP_REST_Request( $_SERVER['REQUEST_METHOD'], $path );
$request->set_query_params( wp_unslash( $_GET ) );
$request->set_body_params( wp_unslash( $_POST ) );
If this request could be added to a last_request
property then parameters can be retrieved by code like $this->last_request->get_query_params()
. This eliminates the need to retrieve values using $_GET and also makes Unit Tests a lot nicer.
Change History (4)
This ticket was mentioned in Slack in #core-restapi by rheinardkorf. View the logs.
8 years ago
Note: See
TracTickets for help on using
tickets.
I think I am -1 on this. Unit tests should use
$request->set_param
, and WP code should use$request->get_param
or just$request['param_name']
. If there are code paths that are doing something else (like #39696 whereWP_REST_Server
checks$_GET
directly) then they should be converted to use regular request parameters instead.