[ Index ] |
PHP Cross Reference of WordPress |
[Source view] [Print] [Project Stats]
REST API: WP_REST_Server class
File Size: | 1800 lines (52 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
WP_REST_Server:: (34 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()
match_request_to_handler()
respond_to_request()
get_json_last_error()
get_index()
add_active_theme_link_to_index()
add_site_logo_to_index()
add_site_icon_to_index()
add_image_to_index()
get_namespace_index()
get_data_for_routes()
get_data_for_route()
get_max_batch_size()
serve_batch_request_v1()
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. since: 4.4.0 |
check_authentication() X-Ref |
Checks the authentication headers if supplied. return: WP_Error|null WP_Error indicates unsuccessful login, null indicates successful since: 4.4.0 |
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. return: WP_REST_Response List of associative arrays with code and message keys. since: 4.4.0 since: 5.7.0 Converted to a wrapper of {@see rest_convert_error_to_response()}. param: WP_Error $error WP_Error instance. |
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. return: string JSON representation of the error since: 4.4.0 param: string $code WP_Error-style code. param: string $message Human-readable message. param: int $status Optional. HTTP status code to send. Default null. |
serve_request( $path = null ) X-Ref |
Handles serving a REST 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. return: null|false Null if not served and a HEAD request, false otherwise. since: 4.4.0 param: string $path Optional. The request route. If not set, `$_SERVER['PATH_INFO']` will be used. |
response_to_data( $response, $embed ) X-Ref |
Converts a response to data to send. return: array { since: 4.4.0 since: 5.4.0 The $embed parameter can now contain a list of link relations to include. param: WP_REST_Response $response Response object. param: bool|string[] $embed Whether to embed all links, a filtered list of link relations, or no links. |
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. return: array Map of link relation to list of link hashes. since: 4.4.0 param: WP_REST_Response $response Response to extract links from. |
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. return: array Map of link relation to list of link hashes. since: 4.5.0 param: WP_REST_Response $response Response to extract links from. |
embed_links( $data, $embed = true ) X-Ref |
Embeds the links from the data into the request. return: array { since: 4.4.0 since: 5.4.0 The $embed parameter can now contain a list of link relations to include. param: array $data Data from the request. param: bool|string[] $embed Whether to embed all links or a filtered list of link relations. |
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. return: WP_REST_Response New response with wrapped data since: 4.4.0 since: 6.0.0 The $embed parameter can now contain a list of link relations to include param: WP_REST_Response $response Response object. param: bool|string[] $embed Whether to embed all links, a filtered list of link relations, or no links. |
register_route( $namespace, $route, $route_args, $override = false ) X-Ref |
Registers a route to the server. since: 4.4.0 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( $namespace = '' ) 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 since: 4.4.0 since: 5.4.0 Add $namespace parameter. param: string $namespace Optionally, only return routes in the given namespace. |
get_namespaces() X-Ref |
Retrieves namespaces registered on the server. return: string[] List of registered namespaces. since: 4.4.0 |
get_route_options( $route ) X-Ref |
Retrieves specified options for a route. return: array|null Data as an associative array if found, or null if not found. since: 4.4.0 param: string $route Route pattern to fetch options for. |
dispatch( $request ) X-Ref |
Matches the request to a callback and call it. return: WP_REST_Response Response returned by the callback. since: 4.4.0 param: WP_REST_Request $request Request to attempt dispatching. |
match_request_to_handler( $request ) X-Ref |
Matches a request object to its handler. return: array|WP_Error The route and request handler on success or a WP_Error instance if no handler was found. since: 5.6.0 param: WP_REST_Request $request The request object. |
respond_to_request( $request, $route, $handler, $response ) X-Ref |
Dispatches the request to the callback handler. return: WP_REST_Response since: 5.6.0 param: WP_REST_Request $request The request object. param: string $route The matched route regex. param: array $handler The matched route handler. param: WP_Error|null $response The current error object if any. |
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: false|string Boolean false or string error message. since: 4.4.0 |
get_index( $request ) X-Ref |
Retrieves the site index. This endpoint describes the capabilities of the site. return: WP_REST_Response The API root index data. since: 4.4.0 param: array $request { |
add_active_theme_link_to_index( WP_REST_Response $response ) X-Ref |
Adds a link to the active theme for users who have proper permissions. since: 5.7.0 param: WP_REST_Response $response REST API response. |
add_site_logo_to_index( WP_REST_Response $response ) X-Ref |
Exposes the site logo through the WordPress REST API. This is used for fetching this information when user has no rights to update settings. since: 5.8.0 param: WP_REST_Response $response REST API response. |
add_site_icon_to_index( WP_REST_Response $response ) X-Ref |
Exposes the site icon through the WordPress REST API. This is used for fetching this information when user has no rights to update settings. since: 5.9.0 param: WP_REST_Response $response REST API response. |
add_image_to_index( WP_REST_Response $response, $image_id, $type ) X-Ref |
Exposes an image through the WordPress REST API. This is used for fetching this information when user has no rights to update settings. since: 5.9.0 param: WP_REST_Response $response REST API response. param: int $image_id Image attachment ID. param: string $type Type of Image. |
get_namespace_index( $request ) X-Ref |
Retrieves the index for a namespace. return: WP_REST_Response|WP_Error WP_REST_Response instance if the index was found, since: 4.4.0 param: WP_REST_Request $request REST request instance. |
get_data_for_routes( $routes, $context = 'view' ) X-Ref |
Retrieves the publicly-visible data for routes. return: array[] Route data to expose in indexes, keyed by route. since: 4.4.0 param: array $routes Routes to get data for. param: string $context Optional. Context for data. Accepts 'view' or 'help'. Default 'view'. |
get_data_for_route( $route, $callbacks, $context = 'view' ) X-Ref |
Retrieves publicly-visible data for the route. return: array|null Data for the route, or null if no publicly-visible data. since: 4.4.0 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'. |
get_max_batch_size() X-Ref |
Gets the maximum number of requests that can be included in a batch. return: int The maximum requests. since: 5.6.0 |
serve_batch_request_v1( WP_REST_Request $batch_request ) X-Ref |
Serves the batch/v1 request. return: WP_REST_Response The generated response object. since: 5.6.0 param: WP_REST_Request $batch_request The batch request object. |
set_status( $code ) X-Ref |
Sends an HTTP status code. since: 4.4.0 param: int $code HTTP status. |
send_header( $key, $value ) X-Ref |
Sends an HTTP header. since: 4.4.0 param: string $key Header key. param: string $value Header value. |
send_headers( $headers ) X-Ref |
Sends multiple HTTP headers. since: 4.4.0 param: array $headers Map of header name to header value. |
remove_header( $key ) X-Ref |
Removes an HTTP header from the current response. since: 4.8.0 param: string $key Header key. |
get_raw_data() X-Ref |
Retrieves the raw request entity (body). return: string Raw request data. since: 4.4.0 |
get_headers( $server ) X-Ref |
Extracts headers from a PHP-style $_SERVER array. return: array Headers extracted from the input. since: 4.4.0 param: array $server Associative array similar to `$_SERVER`. |
Generated: Thu Dec 5 01:00:03 2024 | Cross-referenced by PHPXref 0.7.1 |