加载REST API。

原型

rest_api_loaded()

源文件

路径:wp-includes/rest-api.php

<?php
...
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 );
	// Initialize the server.
	$server = rest_get_server();
	// Fire off the request.
	$route = untrailingslashit( $GLOBALS['wp']->query_vars['rest_route'] );
	if ( empty( $route ) ) {
		$route = '/';
	}
	$server->serve_request( $route );
	// We're done.
	die();
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/rest_api_loaded/