Make WordPress Core

Ticket #45265: 45265.4.diff

File 45265.4.diff, 1.4 KB (added by desrosj, 6 years ago)
  • src/wp-includes/rest-api.php

     
    1717/**
    1818 * Registers a REST API route.
    1919 *
     20 * Note: Do not use before the {@see 'rest_api_init'} hook.
     21 *
    2022 * @since 4.4.0
     23 * @since 5.1.0 Added a _doing_it_wrong() notice when not called on or after the rest_api_init hook.
    2124 *
    2225 * @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin.
    2326 * @param string $route     The base URL for route you are adding.
     
    4144                return false;
    4245        }
    4346
     47        if ( ! did_action( 'rest_api_init' ) ) {
     48                _doing_it_wrong( 'register_rest_route', __( 'REST API routes must be registered on the rest_api_init action.' ), '5.1.0' );
     49        }
     50
    4451        if ( isset( $args['args'] ) ) {
    4552                $common_args = $args['args'];
    4653                unset( $args['args'] );
  • tests/phpunit/tests/rest-api.php

     
    1414 */
    1515class Tests_REST_API extends WP_UnitTestCase {
    1616        public function setUp() {
     17                parent::setUp();
     18
    1719                // Override the normal server with our spying server.
    1820                $GLOBALS['wp_rest_server'] = new Spy_REST_Server();
    19                 parent::setUp();
     21                do_action( 'rest_api_init' );
    2022        }
    2123
    2224        public function tearDown() {