[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

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

REST API: WP_REST_Server class

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

Defines 1 class

WP_REST_Server:: (26 methods):
  __construct()
  check_authentication()
  error_to_response()
  json_error()
  serve_request()
  response_to_data()
  get_response_links()
  get_compact_response_links()
  embed_links()
  envelope_response()
  register_route()
  get_routes()
  get_namespaces()
  get_route_options()
  dispatch()
  get_json_last_error()
  get_index()
  get_namespace_index()
  get_data_for_routes()
  get_data_for_route()
  set_status()
  send_header()
  send_headers()
  remove_header()
  get_raw_data()
  get_headers()


Class: WP_REST_Server  - X-Ref

Core class used to implement the WordPress REST API server.

__construct()   X-Ref
Instantiates the REST server.


check_authentication()   X-Ref
Checks the authentication headers if supplied.

return: WP_Error|null WP_Error indicates unsuccessful login, null indicates successful

error_to_response( $error )   X-Ref
Converts an error to a response object.

This iterates over all error codes and messages to change it into a flat
array. This enables simpler client behaviour, as it is represented as a
list in JSON rather than an object/map.

param: WP_Error $error WP_Error instance.
return: WP_REST_Response List of associative arrays with code and message keys.

json_error( $code, $message, $status = null )   X-Ref
Retrieves an appropriate error representation in JSON.

Note: This should only be used in WP_REST_Server::serve_request(), as it
cannot handle WP_Error internally. All callbacks and other internal methods
should instead return a WP_Error with the data set to an array that includes
a 'status' key, with the value being the HTTP status to send.

param: string $code    WP_Error-style code.
param: string $message Human-readable message.
param: int    $status  Optional. HTTP status code to send. Default null.
return: string JSON representation of the error

serve_request( $path = null )   X-Ref
Handles serving an API request.

Matches the current server URI to a route and runs the first matching
callback then outputs a JSON representation of the returned value.

param: string $path Optional. The request route. If not set, `$_SERVER['PATH_INFO']` will be used.
return: false|null Null if not served and a HEAD request, false otherwise.

response_to_data( $response, $embed )   X-Ref
Converts a response to data to send.

param: WP_REST_Response $response Response object.
param: bool             $embed    Whether links should be embedded.
return: array {

get_response_links( $response )   X-Ref
Retrieves links from a response.

Extracts the links from a response into a structured hash, suitable for
direct output.

param: WP_REST_Response $response Response to extract links from.
return: array Map of link relation to list of link hashes.

get_compact_response_links( $response )   X-Ref
Retrieves the CURIEs (compact URIs) used for relations.

Extracts the links from a response into a structured hash, suitable for
direct output.

param: WP_REST_Response $response Response to extract links from.
return: array Map of link relation to list of link hashes.

embed_links( $data )   X-Ref
Embeds the links from the data into the request.

param: array $data Data from the request.
return: array {

envelope_response( $response, $embed )   X-Ref
Wraps the response in an envelope.

The enveloping technique is used to work around browser/client
compatibility issues. Essentially, it converts the full HTTP response to
data instead.

param: WP_REST_Response $response Response object.
param: bool             $embed    Whether links should be embedded.
return: WP_REST_Response New response with wrapped data

register_route( $namespace, $route, $route_args, $override = false )   X-Ref
Registers a route to the server.

param: string $namespace  Namespace.
param: string $route      The REST route.
param: array  $route_args Route arguments.
param: bool   $override   Optional. Whether the route should be overridden if it already exists.

get_routes()   X-Ref
Retrieves the route map.

The route map is an associative array with path regexes as the keys. The
value is an indexed array with the callback function/method as the first
item, and a bitmask of HTTP methods as the second item (see the class
constants).

Each route can be mapped to more than one callback by using an array of
the indexed arrays. This allows mapping e.g. GET requests to one callback
and POST requests to another.

Note that the path regexes (array keys) must have @ escaped, as this is
used as the delimiter with preg_match()

return: array `'/path/regex' => array( $callback, $bitmask )` or

get_namespaces()   X-Ref
Retrieves namespaces registered on the server.

return: array List of registered namespaces.

get_route_options( $route )   X-Ref
Retrieves specified options for a route.

param: string $route Route pattern to fetch options for.
return: array|null Data as an associative array if found, or null if not found.

dispatch( $request )   X-Ref
Matches the request to a callback and call it.

param: WP_REST_Request $request Request to attempt dispatching.
return: WP_REST_Response Response returned by the callback.

get_json_last_error()   X-Ref
Returns if an error occurred during most recent JSON encode/decode.

Strings to be translated will be in format like
"Encoding error: Maximum stack depth exceeded".

return: bool|string Boolean false or string error message.

get_index( $request )   X-Ref
Retrieves the site index.

This endpoint describes the capabilities of the site.

param: array $request {
return: array Index entity

get_namespace_index( $request )   X-Ref
Retrieves the index for a namespace.

param: WP_REST_Request $request REST request instance.
return: WP_REST_Response|WP_Error WP_REST_Response instance if the index was found,

get_data_for_routes( $routes, $context = 'view' )   X-Ref
Retrieves the publicly-visible data for routes.

param: array  $routes  Routes to get data for.
param: string $context Optional. Context for data. Accepts 'view' or 'help'. Default 'view'.
return: array Route data to expose in indexes.

get_data_for_route( $route, $callbacks, $context = 'view' )   X-Ref
Retrieves publicly-visible data for the route.

param: string $route     Route to get data for.
param: array  $callbacks Callbacks to convert to data.
param: string $context   Optional. Context for the data. Accepts 'view' or 'help'. Default 'view'.
return: array|null Data for the route, or null if no publicly-visible data.

set_status( $code )   X-Ref
Sends an HTTP status code.

param: int $code HTTP status.

send_header( $key, $value )   X-Ref
Sends an HTTP header.

param: string $key Header key.
param: string $value Header value.

send_headers( $headers )   X-Ref
Sends multiple HTTP headers.

param: array $headers Map of header name to header value.

remove_header( $key )   X-Ref
Removes an HTTP header from the current response.

param: string $key Header key.

get_raw_data()   X-Ref
Retrieves the raw request entity (body).

return: string Raw request data.

get_headers( $server )   X-Ref
Extracts headers from a PHP-style $_SERVER array.

param: array $server Associative array similar to `$_SERVER`.
return: array Headers extracted from the input.



Generated: Thu Oct 17 08:20:02 2019 Cross-referenced by PHPXref 0.7