WordPress Version: 4.4
/**
* Loads the REST API.
*
* @since 4.4.0
*
* @global WP $wp Current WordPress environment instance.
* @global WP_REST_Server $wp_rest_server ResponseHandler instance (usually WP_REST_Server).
*/
function rest_api_loaded()
{
if (empty($GLOBALS['wp']->query_vars['rest_route'])) {
return;
}
/**
* Whether this is a REST Request.
*
* @since 4.4.0
* @var bool
*/
define('REST_REQUEST', true);
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
/**
* Filter the REST Server Class.
*
* This filter allows you to adjust the server class used by the API, using a
* different class to handle requests.
*
* @since 4.4.0
*
* @param string $class_name The name of the server class. Default 'WP_REST_Server'.
*/
$wp_rest_server_class = apply_filters('wp_rest_server_class', 'WP_REST_Server');
$wp_rest_server = new $wp_rest_server_class();
/**
* Fires when preparing to serve an API request.
*
* Endpoint objects should be created and register their hooks on this action rather
* than another action to ensure they're only loaded when needed.
*
* @since 4.4.0
*
* @param WP_REST_Server $wp_rest_server Server object.
*/
do_action('rest_api_init', $wp_rest_server);
// Fire off the request.
$wp_rest_server->serve_request($GLOBALS['wp']->query_vars['rest_route']);
// We're done.
die;
}