[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
REST API: WP_REST_Server class
File Size: | 1976 lines (58 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
WP_REST_Server:: (37 methods):
__construct()
check_authentication()
error_to_response()
json_error()
get_json_encode_options()
serve_request()
response_to_data()
get_response_links()
get_target_hints_for_link()
get_compact_response_links()
embed_links()
envelope_response()
register_route()
get_routes()
get_namespaces()
get_route_options()
dispatch()
is_dispatching()
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. |
check_authentication() X-Ref |
Checks the authentication headers if supplied. return: WP_Error|null|true 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 behavior, 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. 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 param: string $code WP_Error-style code. param: string $message Human-readable message. param: int $status Optional. HTTP status code to send. Default null. |
get_json_encode_options( WP_REST_Request $request ) X-Ref |
Gets the encoding options passed to {@see wp_json_encode}. return: int The JSON encode options. param: \WP_REST_Request $request The current request object. |
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. 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 { 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. param: WP_REST_Response $response Response to extract links from. |
get_target_hints_for_link( $link ) X-Ref |
Gets the target links for a REST API Link. return: array|null param: array $link |
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. 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 { 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 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( $route_namespace, $route, $route_args, $override = false ) X-Ref |
Registers a route to the server. param: string $route_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( $route_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 param: string $route_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. |
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. 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. param: WP_REST_Request $request Request to attempt dispatching. |
is_dispatching() X-Ref |
Returns whether the REST server is currently dispatching / responding to a request. This may be a standalone REST API request, or an internal request dispatched from within a regular page load. return: bool Whether the REST server is currently handling a request. |
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. 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 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. |
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. 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. 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. 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. 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. 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, 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. 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. 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. |
serve_batch_request_v1( WP_REST_Request $batch_request ) X-Ref |
Serves the batch/v1 request. return: WP_REST_Response The generated response object. param: WP_REST_Request $batch_request The batch request object. |
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. return: array Headers extracted from the input. param: array $server Associative array similar to `$_SERVER`. |
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |