[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

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

REST API functions.

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

Defines 39 functions

  register_rest_route()
  register_rest_field()
  rest_api_init()
  rest_api_register_rewrites()
  rest_api_default_filters()
  create_initial_rest_routes()
  rest_api_loaded()
  rest_get_url_prefix()
  get_rest_url()
  rest_url()
  rest_do_request()
  rest_get_server()
  rest_ensure_request()
  rest_ensure_response()
  rest_handle_deprecated_function()
  rest_handle_deprecated_argument()
  rest_send_cors_headers()
  rest_handle_options_request()
  rest_send_allow_header()
  rest_filter_response_fields()
  rest_output_rsd()
  rest_output_link_wp_head()
  rest_output_link_header()
  rest_cookie_check_errors()
  rest_cookie_collect_status()
  rest_parse_date()
  rest_get_date_with_gmt()
  rest_authorization_required_code()
  rest_validate_request_arg()
  rest_sanitize_request_arg()
  rest_parse_request_arg()
  rest_is_ip_address()
  rest_sanitize_boolean()
  rest_is_boolean()
  rest_get_avatar_urls()
  rest_get_avatar_sizes()
  rest_validate_value_from_schema()
  rest_sanitize_value_from_schema()
  rest_preload_api_request()

Functions
Functions that are not part of a class:

register_rest_route( $namespace, $route, $args = array()   X-Ref
Registers a REST API route.

Note: Do not use before the {@see 'rest_api_init'} hook.

param: string $namespace The first URL segment after core prefix. Should be unique to your package/plugin.
param: string $route     The base URL for route you are adding.
param: array  $args      Optional. Either an array of options for the endpoint, or an array of arrays for
param: bool   $override  Optional. If the route already exists, should we override it? True overrides,
return: bool True on success, false on error.

register_rest_field( $object_type, $attribute, $args = array()   X-Ref
Registers a new field on an existing WordPress object type.

param: string|array $object_type Object(s) the field is being registered
param: string $attribute         The attribute name.
param: array  $args {

rest_api_init()   X-Ref
Registers rewrite rules for the API.


rest_api_register_rewrites()   X-Ref
Adds REST rewrite rules.


rest_api_default_filters()   X-Ref
Registers the default REST API filters.

Attached to the {@see 'rest_api_init'} action
to make testing and disabling these filters easier.


create_initial_rest_routes()   X-Ref
Registers default REST API routes.


rest_api_loaded()   X-Ref
Loads the REST API.


rest_get_url_prefix()   X-Ref
Retrieves the URL prefix for any API resource.

return: string Prefix.

get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' )   X-Ref
Retrieves the URL to a REST endpoint on a site.

Note: The returned URL is NOT escaped.

param: int    $blog_id Optional. Blog ID. Default of null returns URL for current blog.
param: string $path    Optional. REST route. Default '/'.
param: string $scheme  Optional. Sanitization scheme. Default 'rest'.
return: string Full URL to the endpoint.

rest_url( $path = '', $scheme = 'json' )   X-Ref
Retrieves the URL to a REST endpoint.

Note: The returned URL is NOT escaped.

param: string $path   Optional. REST route. Default empty.
param: string $scheme Optional. Sanitization scheme. Default 'json'.
return: string Full URL to the endpoint.

rest_do_request( $request )   X-Ref
Do a REST request.

Used primarily to route internal requests through WP_REST_Server.

param: WP_REST_Request|string $request Request.
return: WP_REST_Response REST response.

rest_get_server()   X-Ref
Retrieves the current REST server instance.

Instantiates a new instance if none exists already.

return: WP_REST_Server REST server instance.

rest_ensure_request( $request )   X-Ref
Ensures request arguments are a request object (for consistency).

param: array|WP_REST_Request $request Request to check.
return: WP_REST_Request REST request instance.

rest_ensure_response( $response )   X-Ref
Ensures a REST response is a response object (for consistency).

This implements WP_HTTP_Response, allowing usage of `set_status`/`header`/etc
without needing to double-check the object. Will also allow WP_Error to indicate error
responses, so users should immediately check for this value.

param: WP_Error|WP_HTTP_Response|mixed $response Response to check.
return: WP_REST_Response|mixed If response generated an error, WP_Error, if response

rest_handle_deprecated_function( $function, $replacement, $version )   X-Ref
Handles _deprecated_function() errors.

param: string $function    The function that was called.
param: string $replacement The function that should have been called.
param: string $version     Version.

rest_handle_deprecated_argument( $function, $message, $version )   X-Ref
Handles _deprecated_argument() errors.

param: string $function    The function that was called.
param: string $message     A message regarding the change.
param: string $version     Version.

rest_send_cors_headers( $value )   X-Ref
Sends Cross-Origin Resource Sharing headers with API requests.

param: mixed $value Response data.
return: mixed Response data.

rest_handle_options_request( $response, $handler, $request )   X-Ref
Handles OPTIONS requests for the server.

This is handled outside of the server code, as it doesn't obey normal route
mapping.

param: mixed           $response Current response, either response or `null` to indicate pass-through.
param: WP_REST_Server  $handler  ResponseHandler instance (usually WP_REST_Server).
param: WP_REST_Request $request  The request that was used to make current response.
return: WP_REST_Response Modified response, either response or `null` to indicate pass-through.

rest_send_allow_header( $response, $server, $request )   X-Ref
Sends the "Allow" header to state all methods that can be sent to the current route.

param: WP_REST_Response $response Current response being served.
param: WP_REST_Server   $server   ResponseHandler instance (usually WP_REST_Server).
param: WP_REST_Request  $request  The request that was used to make current response.
return: WP_REST_Response Response to be served, with "Allow" header if route has allowed methods.

rest_filter_response_fields( $response, $server, $request )   X-Ref
Filter the API response to include only a white-listed set of response object fields.

param: WP_REST_Response $response Current response being served.
param: WP_REST_Server   $server   ResponseHandler instance (usually WP_REST_Server).
param: WP_REST_Request  $request  The request that was used to make current response.
return: WP_REST_Response Response to be served, trimmed down to contain a subset of fields.

rest_output_rsd()   X-Ref
Adds the REST API URL to the WP RSD endpoint.


rest_output_link_wp_head()   X-Ref
Outputs the REST API link tag into page header.


rest_output_link_header()   X-Ref
Sends a Link header for the REST API.


rest_cookie_check_errors( $result )   X-Ref
Checks for errors when using cookie-based authentication.

WordPress' built-in cookie authentication is always active
for logged in users. However, the API has to check nonces
for each request to ensure users are not vulnerable to CSRF.

param: WP_Error|mixed $result Error from another authentication handler,
return: WP_Error|mixed|bool WP_Error if the cookie is invalid, the $result, otherwise true.

rest_cookie_collect_status()   X-Ref
Collects cookie authentication status.

Collects errors from wp_validate_auth_cookie for use by rest_cookie_check_errors.


rest_parse_date( $date, $force_utc = false )   X-Ref
Parses an RFC3339 time into a Unix timestamp.

param: string $date      RFC3339 timestamp.
param: bool   $force_utc Optional. Whether to force UTC timezone instead of using
return: int Unix timestamp.

rest_get_date_with_gmt( $date, $is_utc = false )   X-Ref
Parses a date into both its local and UTC equivalent, in MySQL datetime format.

param: string $date   RFC3339 timestamp.
param: bool   $is_utc Whether the provided date should be interpreted as UTC. Default false.
return: array|null Local and UTC datetime strings, in MySQL datetime format (Y-m-d H:i:s),

rest_authorization_required_code()   X-Ref
Returns a contextual HTTP error code for authorization failure.

return: integer 401 if the user is not logged in, 403 if the user is logged in.

rest_validate_request_arg( $value, $request, $param )   X-Ref
Validate a request argument based on details registered to the route.

param: mixed            $value
param: WP_REST_Request  $request
param: string           $param
return: WP_Error|boolean

rest_sanitize_request_arg( $value, $request, $param )   X-Ref
Sanitize a request argument based on details registered to the route.

param: mixed            $value
param: WP_REST_Request  $request
param: string           $param
return: mixed

rest_parse_request_arg( $value, $request, $param )   X-Ref
Parse a request argument based on details registered to the route.

Runs a validation check and sanitizes the value, primarily to be used via
the `sanitize_callback` arguments in the endpoint args registration.

param: mixed            $value
param: WP_REST_Request  $request
param: string           $param
return: mixed

rest_is_ip_address( $ip )   X-Ref
Determines if an IP address is valid.

Handles both IPv4 and IPv6 addresses.

param: string $ip IP address.
return: string|false The valid IP address, otherwise false.

rest_sanitize_boolean( $value )   X-Ref
Changes a boolean-like value into the proper boolean value.

param: bool|string|int $value The value being evaluated.
return: boolean Returns the proper associated boolean value.

rest_is_boolean( $maybe_bool )   X-Ref
Determines if a given value is boolean-like.

param: bool|string $maybe_bool The value being evaluated.
return: boolean True if a boolean, otherwise false.

rest_get_avatar_urls( $email )   X-Ref
Retrieves the avatar urls in various sizes based on a given email address.

param: string $email Email address.
return: array $urls Gravatar url for each size.

rest_get_avatar_sizes()   X-Ref
Retrieves the pixel sizes for avatars.

return: array List of pixel sizes for avatars. Default `[ 24, 48, 96 ]`.

rest_validate_value_from_schema( $value, $args, $param = '' )   X-Ref
Validate a value based on a schema.

param: mixed  $value The value to validate.
param: array  $args  Schema array to use for validation.
param: string $param The parameter name, used in error messages.
return: true|WP_Error

rest_sanitize_value_from_schema( $value, $args )   X-Ref
Sanitize a value based on a schema.

param: mixed $value The value to sanitize.
param: array $args  Schema array to use for sanitization.
return: true|WP_Error

rest_preload_api_request( $memo, $path )   X-Ref
Append result of internal request to REST API for purpose of preloading data to be attached to a page.
Expected to be called in the context of `array_reduce`.

param: array  $memo Reduce accumulator.
param: string $path REST API path to preload.
return: array        Modified reduce accumulator.



Generated: Sun Apr 21 08:20:01 2019 Cross-referenced by PHPXref 0.7