[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/rest-api/ -> class-wp-rest-request.php (summary)

REST API: WP_REST_Request class

File Size: 1060 lines (26 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_REST_Request:: (44 methods):
  __construct()
  get_method()
  set_method()
  get_headers()
  canonicalize_header_name()
  get_header()
  get_header_as_array()
  set_header()
  add_header()
  remove_header()
  set_headers()
  get_content_type()
  is_json_content_type()
  get_parameter_order()
  get_param()
  has_param()
  set_param()
  get_params()
  get_url_params()
  set_url_params()
  get_query_params()
  set_query_params()
  get_body_params()
  set_body_params()
  get_file_params()
  set_file_params()
  get_default_params()
  set_default_params()
  get_body()
  set_body()
  get_json_params()
  parse_json_params()
  parse_body_params()
  get_route()
  set_route()
  get_attributes()
  set_attributes()
  sanitize_params()
  has_valid_params()
  offsetExists()
  offsetGet()
  offsetSet()
  offsetUnset()
  from_url()


Class: WP_REST_Request  - X-Ref

Core class used to implement a REST request object.

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 behaviour 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.

__construct( $method = '', $route = '', $attributes = array()   X-Ref
Constructor.

since: 4.4.0
param: string $method     Optional. Request method. Default empty.
param: string $route      Optional. Request route. Default empty.
param: array  $attributes Optional. Request attributes. Default empty array.

get_method()   X-Ref
Retrieves the HTTP method for the request.

return: string HTTP method.
since: 4.4.0

set_method( $method )   X-Ref
Sets HTTP method for the request.

since: 4.4.0
param: string $method HTTP method.

get_headers()   X-Ref
Retrieves all headers from the request.

return: array Map of key to value. Key is always lowercase, as per HTTP specification.
since: 4.4.0

canonicalize_header_name( $key )   X-Ref
Canonicalizes the header name.

Ensures that header names are always treated the same regardless of
source. Header names are always case insensitive.

Note that we treat `-` (dashes) and `_` (underscores) as the same
character, as per header parsing rules in both Apache and nginx.

return: string Canonicalized name.
since: 4.4.0
param: string $key Header name.

get_header( $key )   X-Ref
Retrieves the given header from the request.

If the header has multiple values, they will be concatenated with a comma
as per the HTTP specification. Be aware that some non-compliant headers
(notably cookie headers) cannot be joined this way.

return: string|null String value if set, null otherwise.
since: 4.4.0
param: string $key Header name, will be canonicalized to lowercase.

get_header_as_array( $key )   X-Ref
Retrieves header values from the request.

return: array|null List of string values if set, null otherwise.
since: 4.4.0
param: string $key Header name, will be canonicalized to lowercase.

set_header( $key, $value )   X-Ref
Sets the header on request.

since: 4.4.0
param: string $key   Header name.
param: string $value Header value, or list of values.

add_header( $key, $value )   X-Ref
Appends a header value for the given header.

since: 4.4.0
param: string $key   Header name.
param: string $value Header value, or list of values.

remove_header( $key )   X-Ref
Removes all values for a header.

since: 4.4.0
param: string $key Header name.

set_headers( $headers, $override = true )   X-Ref
Sets headers on the request.

since: 4.4.0
param: array $headers  Map of header name to value.
param: bool  $override If true, replace the request's headers. Otherwise, merge with existing.

get_content_type()   X-Ref
Retrieves the content-type of the request.

return: array|null Map containing 'value' and 'parameters' keys
since: 4.4.0

is_json_content_type()   X-Ref
Checks if the request has specified a JSON content-type.

return: bool True if the content-type header is JSON.
since: 5.6.0

get_parameter_order()   X-Ref
Retrieves the parameter priority order.

Used when checking parameters in WP_REST_Request::get_param().

return: string[] Array of types to check, in order of priority.
since: 4.4.0

get_param( $key )   X-Ref
Retrieves a parameter from the request.

return: mixed|null Value if set, null otherwise.
since: 4.4.0
param: string $key Parameter name.

has_param( $key )   X-Ref
Checks if a parameter exists in the request.

This allows distinguishing between an omitted parameter,
and a parameter specifically set to null.

return: bool True if a param exists for the given key.
since: 5.3.0
param: string $key Parameter name.

set_param( $key, $value )   X-Ref
Sets a parameter on the request.

If the given parameter key exists in any parameter type an update will take place,
otherwise a new param will be created in the first parameter type (respecting
get_parameter_order()).

since: 4.4.0
param: string $key   Parameter name.
param: mixed  $value Parameter value.

get_params()   X-Ref
Retrieves merged parameters from the request.

The equivalent of get_param(), but returns all parameters for the request.
Handles merging all the available values into a single array.

return: array Map of key to value.
since: 4.4.0

get_url_params()   X-Ref
Retrieves parameters from the route itself.

These are parsed from the URL using the regex.

return: array Parameter map of key to value.
since: 4.4.0

set_url_params( $params )   X-Ref
Sets parameters from the route.

Typically, this is set after parsing the URL.

since: 4.4.0
param: array $params Parameter map of key to value.

get_query_params()   X-Ref
Retrieves parameters from the query string.

These are the parameters you'd typically find in `$_GET`.

return: array Parameter map of key to value
since: 4.4.0

set_query_params( $params )   X-Ref
Sets parameters from the query string.

Typically, this is set from `$_GET`.

since: 4.4.0
param: array $params Parameter map of key to value.

get_body_params()   X-Ref
Retrieves parameters from the body.

These are the parameters you'd typically find in `$_POST`.

return: array Parameter map of key to value.
since: 4.4.0

set_body_params( $params )   X-Ref
Sets parameters from the body.

Typically, this is set from `$_POST`.

since: 4.4.0
param: array $params Parameter map of key to value.

get_file_params()   X-Ref
Retrieves multipart file parameters from the body.

These are the parameters you'd typically find in `$_FILES`.

return: array Parameter map of key to value
since: 4.4.0

set_file_params( $params )   X-Ref
Sets multipart file parameters from the body.

Typically, this is set from `$_FILES`.

since: 4.4.0
param: array $params Parameter map of key to value.

get_default_params()   X-Ref
Retrieves the default parameters.

These are the parameters set in the route registration.

return: array Parameter map of key to value
since: 4.4.0

set_default_params( $params )   X-Ref
Sets default parameters.

These are the parameters set in the route registration.

since: 4.4.0
param: array $params Parameter map of key to value.

get_body()   X-Ref
Retrieves the request body content.

return: string Binary data from the request body.
since: 4.4.0

set_body( $data )   X-Ref
Sets body content.

since: 4.4.0
param: string $data Binary data from the request body.

get_json_params()   X-Ref
Retrieves the parameters from a JSON-formatted body.

return: array Parameter map of key to value.
since: 4.4.0

parse_json_params()   X-Ref
Parses the JSON parameters.

Avoids parsing the JSON data until we need to access it.

return: true|WP_Error True if the JSON data was passed or no JSON data was provided, WP_Error if invalid JSON was passed.
since: 4.4.0
since: 4.7.0 Returns error instance if value cannot be decoded.

parse_body_params()   X-Ref
Parses the request body parameters.

Parses out URL-encoded bodies for request methods that aren't supported
natively by PHP. In PHP 5.x, only POST has these parsed automatically.

since: 4.4.0

get_route()   X-Ref
Retrieves the route that matched the request.

return: string Route matching regex.
since: 4.4.0

set_route( $route )   X-Ref
Sets the route that matched the request.

since: 4.4.0
param: string $route Route matching regex.

get_attributes()   X-Ref
Retrieves the attributes for the request.

These are the options for the route that was matched.

return: array Attributes for the request.
since: 4.4.0

set_attributes( $attributes )   X-Ref
Sets the attributes for the request.

since: 4.4.0
param: array $attributes Attributes for the request.

sanitize_params()   X-Ref
Sanitizes (where possible) the params on the request.

This is primarily based off the sanitize_callback param on each registered
argument.

return: true|WP_Error True if parameters were sanitized, WP_Error if an error occurred during sanitization.
since: 4.4.0

has_valid_params()   X-Ref
Checks whether this request is valid according to its attributes.

return: true|WP_Error True if there are no parameters to validate or if all pass validation,
since: 4.4.0

offsetExists( $offset )   X-Ref
Checks if a parameter is set.

return: bool Whether the parameter is set.
since: 4.4.0
param: string $offset Parameter name.

offsetGet( $offset )   X-Ref
Retrieves a parameter from the request.

return: mixed|null Value if set, null otherwise.
since: 4.4.0
param: string $offset Parameter name.

offsetSet( $offset, $value )   X-Ref
Sets a parameter on the request.

since: 4.4.0
param: string $offset Parameter name.
param: mixed  $value  Parameter value.

offsetUnset( $offset )   X-Ref
Removes a parameter from the request.

since: 4.4.0
param: string $offset Parameter name.

from_url( $url )   X-Ref
Retrieves a WP_REST_Request object from a full URL.

return: WP_REST_Request|false WP_REST_Request object on success, false on failure.
since: 4.5.0
param: string $url URL with protocol, domain, path and query args.



Generated: Thu Dec 5 01:00:03 2024 Cross-referenced by PHPXref 0.7.1