diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
index 3b158ea..06bb9f9 100644
a
|
b
|
define( 'REST_API_VERSION', '2.0' ); |
19 | 19 | * |
20 | 20 | * @since 4.4.0 |
21 | 21 | * |
22 | | * @global WP_REST_Server $wp_rest_server ResponseHandler instance (usually WP_REST_Server). |
23 | | * |
24 | 22 | * @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin. |
25 | 23 | * @param string $route The base URL for route you are adding. |
26 | 24 | * @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for |
… |
… |
define( 'REST_API_VERSION', '2.0' ); |
30 | 28 | * @return bool True on success, false on error. |
31 | 29 | */ |
32 | 30 | function register_rest_route( $namespace, $route, $args = array(), $override = false ) { |
33 | | /** @var WP_REST_Server $wp_rest_server */ |
34 | | global $wp_rest_server; |
35 | | |
36 | 31 | if ( empty( $namespace ) ) { |
37 | 32 | /* |
38 | 33 | * Non-namespaced routes are not allowed, with the exception of the main |
… |
… |
function register_rest_route( $namespace, $route, $args = array(), $override = f |
74 | 69 | } |
75 | 70 | |
76 | 71 | $full_route = '/' . trim( $namespace, '/' ) . '/' . trim( $route, '/' ); |
77 | | $wp_rest_server->register_route( $namespace, $full_route, $args, $override ); |
| 72 | rest_get_server()->register_route( $namespace, $full_route, $args, $override ); |
78 | 73 | return true; |
79 | 74 | } |
80 | 75 | |
… |
… |
function create_initial_rest_routes() { |
245 | 240 | * @since 4.4.0 |
246 | 241 | * |
247 | 242 | * @global WP $wp Current WordPress environment instance. |
248 | | * @global WP_REST_Server $wp_rest_server ResponseHandler instance (usually WP_REST_Server). |
249 | 243 | */ |
250 | 244 | function rest_api_loaded() { |
251 | 245 | if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) { |
… |
… |
function rest_url( $path = '', $scheme = 'json' ) { |
387 | 381 | * |
388 | 382 | * @since 4.4.0 |
389 | 383 | * |
390 | | * @global WP_REST_Server $wp_rest_server ResponseHandler instance (usually WP_REST_Server). |
391 | | * |
392 | 384 | * @param WP_REST_Request|string $request Request. |
393 | 385 | * @return WP_REST_Response REST response. |
394 | 386 | */ |
… |
… |
function rest_output_link_header() { |
704 | 696 | * @since 4.4.0 |
705 | 697 | * |
706 | 698 | * @global mixed $wp_rest_auth_cookie |
707 | | * @global WP_REST_Server $wp_rest_server REST server instance. |
708 | 699 | * |
709 | 700 | * @param WP_Error|mixed $result Error from another authentication handler, |
710 | 701 | * null if we should handle it, or another value |
… |
… |
function rest_cookie_check_errors( $result ) { |
716 | 707 | return $result; |
717 | 708 | } |
718 | 709 | |
719 | | global $wp_rest_auth_cookie, $wp_rest_server; |
| 710 | global $wp_rest_auth_cookie; |
720 | 711 | |
721 | 712 | /* |
722 | 713 | * Is cookie authentication being used? (If we get an auth |
… |
… |
function rest_cookie_check_errors( $result ) { |
750 | 741 | } |
751 | 742 | |
752 | 743 | // Send a refreshed nonce in header. |
753 | | $wp_rest_server->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) ); |
| 744 | rest_get_server()->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) ); |
754 | 745 | |
755 | 746 | return true; |
756 | 747 | } |
diff --git a/tests/phpunit/tests/rest-api.php b/tests/phpunit/tests/rest-api.php
index 689cbdf..90a480d 100644
a
|
b
|
class Tests_REST_API extends WP_UnitTestCase { |
16 | 16 | public function setUp() { |
17 | 17 | // Override the normal server with our spying server. |
18 | 18 | $GLOBALS['wp_rest_server'] = new Spy_REST_Server(); |
19 | | parent::setup(); |
| 19 | parent::setUp(); |
| 20 | } |
| 21 | |
| 22 | public function tearDown() { |
| 23 | remove_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) ); |
| 24 | parent::tearDown(); |
20 | 25 | } |
21 | 26 | |
22 | 27 | /** |
… |
… |
class Tests_REST_API extends WP_UnitTestCase { |
446 | 451 | public function test_rest_parse_date_force_utc( $string, $value ) { |
447 | 452 | $this->assertEquals( $value, rest_parse_date( $string, true ) ); |
448 | 453 | } |
| 454 | |
| 455 | public function filter_wp_rest_server_class( $class_name ) { |
| 456 | return 'Spy_REST_Server'; |
| 457 | } |
| 458 | |
| 459 | public function test_register_rest_route_without_server() { |
| 460 | $GLOBALS['wp_rest_server'] = null; |
| 461 | add_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) ); |
| 462 | |
| 463 | register_rest_route( 'test-ns', '/test', array( |
| 464 | 'methods' => array( 'GET' ), |
| 465 | 'callback' => '__return_null', |
| 466 | ) ); |
| 467 | |
| 468 | $routes = $GLOBALS['wp_rest_server']->get_routes(); |
| 469 | $this->assertEquals( $routes['/test-ns/test'][0]['methods'], array( 'GET' => true ) ); |
| 470 | } |
449 | 471 | } |