Make WordPress Core

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's profile 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)

#1 @rheinardkorf
8 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.


8 years ago

#3 @jnylen0
8 years ago

  • Keywords close added

I think I am -1 on this. Unit tests should use $request->set_query_param, and WP code should use $request->get_query_param or $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.

Version 0, edited 8 years ago by jnylen0 (next)

#4 @TimothyBlynJacobs
4 years ago

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

Agreed. Closing.

Note: See TracTickets for help on using tickets.