WP_REST_Server
- Since
- 4.4.0
- Source
wp-includes/rest-api/class-wp-rest-server.php:15
Core class used to implement the WordPress REST API server.
Compatibility
- WordPress
- since 4.4.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 24
Every hook that fires from inside WP_REST_Server, in the order it appears in the class, grouped by the method that fires it.
WP_REST_Server::serve_request()
- apply_filters( rest_jsonp_enabled )filter line 316
- do_action( rest_enabled )filter_deprecated line 348
- apply_filters( rest_exposed_cors_headers )filter line 408
- apply_filters( rest_allowed_cors_headers )filter line 434
- apply_filters( rest_post_dispatch )filter line 464
- apply_filters( rest_send_nocache_headers )filter line 487
- apply_filters( rest_pre_serve_request )filter line 516
- apply_filters( rest_pre_echo_response )filter line 539
WP_REST_Server::get_routes()
- apply_filters( rest_endpoints )filter line 974
WP_REST_Server::dispatch()
- apply_filters( rest_pre_dispatch )filter line 1079
WP_REST_Server::respond_to_request()
- apply_filters( rest_request_before_callbacks )filter line 1256
- apply_filters( rest_dispatch_request )filter line 1287
- apply_filters( rest_request_after_callbacks )filter line 1318
WP_REST_Server::get_index()
- apply_filters( rest_index )filter line 1416
WP_REST_Server::get_data_for_routes()
- apply_filters( rest_endpoints_description )filter line 1579
- apply_filters( rest_route_data )filter line 1594
WP_REST_Server::serve_batch_request_v1()
- apply_filters( rest_pre_dispatch )filter line 1840
- apply_filters( rest_post_dispatch )filter line 1868
Properties · 5
$namespacesarrayprotected- Namespaces registered to the server.
$endpointsarrayprotected- Endpoints registered to the server.
$route_optionsarrayprotected- Options defined for the routes.
$embed_cachearrayprotected- Caches embedded requests.
$dispatching_requestsarrayprotected- Stores request objects that are currently being handled.
Methods · 37
- __construct()Instantiates the REST server.
- check_authentication()Checks the authentication headers if supplied.
- error_to_response()Converts an error to a response object.
- json_error()Retrieves an appropriate error representation in JSON.
- get_json_encode_options()Gets the encoding options passed to {@see wp_json_encode}.
- serve_request()Handles serving a REST API request.
- response_to_data()Converts a response to data to send.
- get_response_links()Retrieves links from a response.
- get_target_hints_for_link()Gets the target hints for a REST API Link.
- get_compact_response_links()Retrieves the CURIEs (compact URIs) used for relations.
- embed_links()Embeds the links from the data into the request.
- envelope_response()Wraps the response in an envelope.
- register_route()Registers a route to the server.
- get_routes()Retrieves the route map.
- get_namespaces()Retrieves namespaces registered on the server.
- get_route_options()Retrieves specified options for a route.
- dispatch()Matches the request to a callback and call it.
- is_dispatching()Returns whether the REST server is currently dispatching / responding to a request.
- match_request_to_handler()Matches a request object to its handler.
- respond_to_request()Dispatches the request to the callback handler.
- get_json_last_error()Returns if an error occurred during most recent JSON encode/decode.
- get_index()Retrieves the site index.
- add_active_theme_link_to_index()Adds a link to the active theme for users who have proper permissions.
- add_site_logo_to_index()Exposes the site logo through the WordPress REST API.
- add_site_icon_to_index()Exposes the site icon through the WordPress REST API.
- add_image_to_index()Exposes an image through the WordPress REST API.
- get_namespace_index()Retrieves the index for a namespace.
- get_data_for_routes()Retrieves the publicly-visible data for routes.
- get_data_for_route()Retrieves publicly-visible data for the route.
- get_max_batch_size()Gets the maximum number of requests that can be included in a batch.
- serve_batch_request_v1()Serves the batch/v1 request.
- set_status()Sends an HTTP status code.
- send_header()Sends an HTTP header.
- send_headers()Sends multiple HTTP headers.
- remove_header()Removes an HTTP header from the current response.
- get_raw_data()Retrieves the raw request entity (body).
- get_headers()Extracts headers from a PHP-style $_SERVER array.
Source code
#[AllowDynamicProperties]class WP_REST_Server { /** * Alias for GET transport method. * * @since 4.4.0 * @var string */ const READABLE = 'GET'; /** * Alias for POST transport method. * * @since 4.4.0 * @var string */ const CREATABLE = 'POST'; /** * Alias for POST, PUT, PATCH transport methods together. * * @since 4.4.0 * @var string */ const EDITABLE = 'POST, PUT, PATCH'; /** * Alias for DELETE transport method. * * @since 4.4.0 * @var string */ const DELETABLE = 'DELETE'; /** * Alias for GET, POST, PUT, PATCH & DELETE transport methods together. * * @since 4.4.0 * @var string */ const ALLMETHODS = 'GET, POST, PUT, PATCH, DELETE'; /** * Namespaces registered to the server. * * @since 4.4.0 * @var array */ protected $namespaces = array(); /** * Endpoints registered to the server. * * @since 4.4.0 * @var array */ protected $endpoints = array(); /** * Options defined for the routes. * * @since 4.4.0 * @var array */ protected $route_options = array(); /** * Caches embedded requests. * * @since 5.4.0 * @var array */ protected $embed_cache = array(); /** * Stores request objects that are currently being handled. * * @since 6.5.0 * @var arrayChangelog
Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/rest-api/class-wp-rest-server.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.