REST API: Always call rest_get_server() instead of accessing the $wp_rest_server global.

This is a consistency improvement and also a bug fix for fairly obscure cases involving modified WP load order.

Fixes #41555.

Built from https://develop.svn.wordpress.org/trunk@41238


git-svn-id: http://core.svn.wordpress.org/trunk@41078 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
James Nylen 2017-08-10 01:38:43 +00:00
parent e183d59acb
commit fce0b2dcd9
2 changed files with 4 additions and 13 deletions

View File

@ -19,8 +19,6 @@ define( 'REST_API_VERSION', '2.0' );
*
* @since 4.4.0
*
* @global WP_REST_Server $wp_rest_server ResponseHandler instance (usually WP_REST_Server).
*
* @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin.
* @param string $route The base URL for route you are adding.
* @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for
@ -30,9 +28,6 @@ define( 'REST_API_VERSION', '2.0' );
* @return bool True on success, false on error.
*/
function register_rest_route( $namespace, $route, $args = array(), $override = false ) {
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
if ( empty( $namespace ) ) {
/*
* Non-namespaced routes are not allowed, with the exception of the main
@ -74,7 +69,7 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
}
$full_route = '/' . trim( $namespace, '/' ) . '/' . trim( $route, '/' );
$wp_rest_server->register_route( $namespace, $full_route, $args, $override );
rest_get_server()->register_route( $namespace, $full_route, $args, $override );
return true;
}
@ -245,7 +240,6 @@ function create_initial_rest_routes() {
* @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'] ) ) {
@ -387,8 +381,6 @@ function rest_url( $path = '', $scheme = 'json' ) {
*
* @since 4.4.0
*
* @global WP_REST_Server $wp_rest_server ResponseHandler instance (usually WP_REST_Server).
*
* @param WP_REST_Request|string $request Request.
* @return WP_REST_Response REST response.
*/
@ -704,7 +696,6 @@ function rest_output_link_header() {
* @since 4.4.0
*
* @global mixed $wp_rest_auth_cookie
* @global WP_REST_Server $wp_rest_server REST server instance.
*
* @param WP_Error|mixed $result Error from another authentication handler,
* null if we should handle it, or another value
@ -716,7 +707,7 @@ function rest_cookie_check_errors( $result ) {
return $result;
}
global $wp_rest_auth_cookie, $wp_rest_server;
global $wp_rest_auth_cookie;
/*
* Is cookie authentication being used? (If we get an auth
@ -750,7 +741,7 @@ function rest_cookie_check_errors( $result ) {
}
// Send a refreshed nonce in header.
$wp_rest_server->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) );
rest_get_server()->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) );
return true;
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41237';
$wp_version = '4.9-alpha-41238';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.