From a0e8d315906268252cb3ec59061bdbb899a326ee Mon Sep 17 00:00:00 2001 From: TimothyBlynJacobs Date: Sun, 25 Aug 2024 22:51:14 +0000 Subject: [PATCH] REST API: Improve error messages when registering an invalid route. The error messages now include the REST API namespace and route to help identify the offending code. Props lwangaman, timothyblynjacobs. Fixes #50493. Built from https://develop.svn.wordpress.org/trunk@58933 git-svn-id: http://core.svn.wordpress.org/trunk@58329 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/rest-api.php | 43 +++++++++++++++++++++++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php index 7aa2534520..9b023e97ec 100644 --- a/wp-includes/rest-api.php +++ b/wp-includes/rest-api.php @@ -38,26 +38,55 @@ function register_rest_route( $route_namespace, $route, $args = array(), $overri * and namespace indexes. If you really need to register a * non-namespaced route, call `WP_REST_Server::register_route` directly. */ - _doing_it_wrong( 'register_rest_route', __( 'Routes must be namespaced with plugin or theme name and version.' ), '4.4.0' ); + _doing_it_wrong( + __FUNCTION__, + sprintf( + /* translators: 1: string value of the namespace, 2: string value of the route. */ + __( 'Routes must be namespaced with plugin or theme name and version. Instead there seems to be an empty namespace \'%1$s\' for route \'%2$s\'.' ), + '' . $route_namespace . '', + '' . $route . '' + ), + '4.4.0' + ); return false; } elseif ( empty( $route ) ) { - _doing_it_wrong( 'register_rest_route', __( 'Route must be specified.' ), '4.4.0' ); + _doing_it_wrong( + __FUNCTION__, + sprintf( + /* translators: 1: string value of the namespace, 2: string value of the route. */ + __( 'Route must be specified. Instead within the namespace \'%1$s\', there seems to be an empty route \'%2$s\'.' ), + '' . $route_namespace . '', + '' . $route . '' + ), + '4.4.0' + ); return false; } $clean_namespace = trim( $route_namespace, '/' ); if ( $clean_namespace !== $route_namespace ) { - _doing_it_wrong( __FUNCTION__, __( 'Namespace must not start or end with a slash.' ), '5.4.2' ); + _doing_it_wrong( + __FUNCTION__, + sprintf( + /* translators: 1: string value of the namespace, 2: string value of the route. */ + __( 'Namespace must not start or end with a slash. Instead namespace \'%1$s\' for route \'%2$s\' seems to contain a slash.' ), + '' . $route_namespace . '', + '' . $route . '' + ), + '5.4.2' + ); } if ( ! did_action( 'rest_api_init' ) ) { _doing_it_wrong( - 'register_rest_route', + __FUNCTION__, sprintf( - /* translators: %s: rest_api_init */ - __( 'REST API routes must be registered on the %s action.' ), - 'rest_api_init' + /* translators: 1: rest_api_init, 2: string value of the route, 3: string value of the namespace. */ + __( 'REST API routes must be registered on the %1$s action. Instead route \'%2$s\' with namespace \'%3$s\' was not registered on this action.' ), + 'rest_api_init', + '' . $route . '', + '' . $route_namespace . '' ), '5.1.0' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index bbac76b09e..97bed631a2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.7-alpha-58932'; +$wp_version = '6.7-alpha-58933'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.