Make WordPress Core

Ticket #45265: 45265.diff

File 45265.diff, 1.1 KB (added by kraftbj, 6 years ago)

Throw a _doing_it_wrong. Assuming 5.1.0.

  • src/wp-includes/rest-api.php

     
    1818 * Registers a REST API route.
    1919 *
    2020 * @since 4.4.0
     21 * @since 5.1.0 Enforce requirement to use on the rest_api_init hook.
     22 *
    2123 *
    2224 * @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin.
    2325 * @param string $route     The base URL for route you are adding.
     
    2830 * @return bool True on success, false on error.
    2931 */
    3032function register_rest_route( $namespace, $route, $args = array(), $override = false ) {
    31         if ( empty( $namespace ) ) {
     33        if ( ! doing_action( 'rest_api_init' ) ) {
     34                _doing_it_wrong( 'register_rest_route', __( 'REST API routes must be registered on the rest_api_init action.'), '5.1.0' );
     35                return false;
     36        } else if ( empty( $namespace ) ) {
    3237                /*
    3338                 * Non-namespaced routes are not allowed, with the exception of the main
    3439                 * and namespace indexes. If you really need to register a