WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#39727 new enhancement

REST API: Add $last_request property to WP_REST_Server as per Spy_REST_Server.

Reported by: rheinardkorf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.2
Component: REST API Keywords: close
Focuses: rest-api Cc:
PR Number:

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

#1 @rheinardkorf
3 years ago

  • Component changed from General to REST API
  • Focuses rest-api added

This ticket was mentioned in Slack in #core-restapi by rheinardkorf. View the logs.


3 years ago

#3 @jnylen0
3 years ago

  • Keywords close added

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 where WP_REST_Server checks $_GET directly) then they should be converted to use regular request parameters instead.

Last edited 3 years ago by jnylen0 (previous) (diff)
Note: See TracTickets for help on using tickets.