wppaste
WordPress

WP_REST_Request

Since
4.4.0
Source
wp-includes/rest-api/class-wp-rest-request.php:29
Core class used to implement a REST request object.

Description

Contains data from the request, to be passed to the callback.

Note: This implements ArrayAccess, and acts as an array of parameters when used in that manner. It does not use ArrayObject (as we cannot rely on SPL), so be aware it may have non-array behavior in some cases.

Note: When using features provided by ArrayAccess, be aware that WordPress deliberately does not distinguish between arguments of the same name for different request methods.
For instance, in a request with GET id=1 and POST id=2, $request['id'] will equal 2 (POST) not 1 (GET). For more precision between request methods, use WP_REST_Request::get_body_params(), WP_REST_Request::get_url_params(), etc.

Compatibility

WordPress
since 4.4.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Hooks and filters fired · 2

Every hook that fires from inside WP_REST_Request, in the order it appears in the class, grouped by the method that fires it.

Properties · 8

$methodstringprotected
HTTP method.
$paramsarrayprotected
Parameters passed to the request.
$headersarrayprotected
HTTP headers for the request.
$bodystringprotected
Body data.
$routestringprotected
Route matched for the request.
$attributesarrayprotected
Attributes (options) for the route that was matched.
$parsed_jsonboolprotected
Used to determine if the JSON data has been parsed yet.
$parsed_bodyboolprotected
Used to determine if the body data has been parsed yet.

Methods · 45

Source code

#[AllowDynamicProperties]class WP_REST_Request implements ArrayAccess { 	/**	 * HTTP method.	 *	 * @since 4.4.0	 * @var string	 */	protected $method = ''; 	/**	 * Parameters passed to the request.	 *	 * These typically come from the `$_GET`, `$_POST` and `$_FILES`	 * superglobals when being created from the global scope.	 *	 * @since 4.4.0	 * @var array Contains GET, POST and FILES keys mapping to arrays of data.	 */	protected $params; 	/**	 * HTTP headers for the request.	 *	 * @since 4.4.0	 * @var array Map of key to value. Key is always lowercase, as per HTTP specification.	 */	protected $headers = array(); 	/**	 * Body data.	 *	 * @since 4.4.0	 * @var string Binary data from the request.	 */	protected $body = null; 	/**	 * Route matched for the request.	 *	 * @since 4.4.0	 * @var string	 */	protected $route; 	/**	 * Attributes (options) for the route that was matched.	 *	 * This is the options array used when the route was registered, typically	 * containing the callback as well as the valid methods for the route.	 *	 * @since 4.4.0	 * @var array Attributes for the request.	 */	protected $attributes = array(); 	/**	 * Used to determine if the JSON data has been parsed yet.	 *	 * Allows lazy-parsing of JSON data where possible.	 *	 * @since 4.4.0	 * @var bool	 */	protected $parsed_json = false; 	/**	 * Used to determine if the body data has been parsed yet.	 *	 * @since 4.4.0	 * @var bool	 */	protected $parsed_body = false; 	/**	 * Constructor.	 *	 * @since 4.4.0	 *

Changelog

Introduced in 4.4.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.8.8
Method is_method() added.verified against source
4.4.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/rest-api/class-wp-rest-request.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.