WP_REST_Request
- Since
- 4.4.0
- Source
wp-includes/rest-api/class-wp-rest-request.php:29
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
- __construct()Constructor.
- get_method()Retrieves the HTTP method for the request.
- set_method()Sets HTTP method for the request.
- get_headers()Retrieves all headers from the request.
- is_method()Determines if the request is the given method.
- canonicalize_header_name()Canonicalizes the header name.
- get_header()Retrieves the given header from the request.
- get_header_as_array()Retrieves header values from the request.
- set_header()Sets the header on request.
- add_header()Appends a header value for the given header.
- remove_header()Removes all values for a header.
- set_headers()Sets headers on the request.
- get_content_type()Retrieves the Content-Type of the request.
- is_json_content_type()Checks if the request has specified a JSON Content-Type.
- get_parameter_order()Retrieves the parameter priority order.
- get_param()Retrieves a parameter from the request.
- has_param()Checks if a parameter exists in the request.
- set_param()Sets a parameter on the request.
- get_params()Retrieves merged parameters from the request.
- get_url_params()Retrieves parameters from the route itself.
- set_url_params()Sets parameters from the route.
- get_query_params()Retrieves parameters from the query string.
- set_query_params()Sets parameters from the query string.
- get_body_params()Retrieves parameters from the body.
- set_body_params()Sets parameters from the body.
- get_file_params()Retrieves multipart file parameters from the body.
- set_file_params()Sets multipart file parameters from the body.
- get_default_params()Retrieves the default parameters.
- set_default_params()Sets default parameters.
- get_body()Retrieves the request body content.
- set_body()Sets body content.
- get_json_params()Retrieves the parameters from a JSON-formatted body.
- parse_json_params()Parses the JSON parameters.
- parse_body_params()Parses the request body parameters.
- get_route()Retrieves the route that matched the request.
- set_route()Sets the route that matched the request.
- get_attributes()Retrieves the attributes for the request.
- set_attributes()Sets the attributes for the request.
- sanitize_params()Sanitizes (where possible) the params on the request.
- has_valid_params()Checks whether this request is valid according to its attributes.
- offsetExists()Checks if a parameter is set.
- offsetGet()Retrieves a parameter from the request.
- offsetSet()Sets a parameter on the request.
- offsetUnset()Removes a parameter from the request.
- from_url()Retrieves a WP_REST_Request object from a full URL.
Changelog
Introduced in 4.4.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
is_method() added.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.