From aa2f10e5d8ee854f597250fca963e44efdd899ae Mon Sep 17 00:00:00 2001 From: "John R. D'Orazio" Date: Thu, 16 Jul 2020 22:15:07 +0200 Subject: [PATCH 1/4] Update rest-api.php --- src/wp-includes/rest-api.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index d3bb80a3d6..d6db464c0e 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -37,25 +37,27 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f * 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( 'register_rest_route', __( 'Routes must be namespaced with plugin or theme name and version.' ) . ' [Namespace = "' . $namespace . '", Route = "' . $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( 'register_rest_route', __( 'Route must be specified.' ) . ' [Namespace = "' . $namespace . '", Route = "' . $route . '"]', '4.4.0' ); return false; } $clean_namespace = trim( $namespace, '/' ); if ( $clean_namespace !== $namespace ) { - _doing_it_wrong( __FUNCTION__, __( 'Namespace must not start or end with a slash.' ), '5.4.2' ); + _doing_it_wrong( + __FUNCTION__, + __( 'Namespace must not start or end with a slash.' ) . ' [Namespace = "' . $namespace . '", Route = "' . $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 routes must be registered on the %s action.' ) . ' [Namespace = "' . $namespace . '", Route = "' . $route . '"]', 'rest_api_init' ), '5.1.0' @@ -1835,7 +1837,7 @@ function rest_sanitize_value_from_schema( $value, $args, $param = '' ) { _doing_it_wrong( __FUNCTION__, /* translators: 1. Parameter. 2. The list of allowed types. */ - wp_sprintf( __( 'The "type" schema keyword for %1$s can only be on of the built-in types: %2$l.' ), $param, $allowed_types ), + wp_sprintf( __( 'The "type" schema keyword for %1$s can only be one of the built-in types: %2$l.' ), $param, $allowed_types ), '5.5.0' ); } From 059bee8c0f63f9540c9fa37e0ed56c69932e7227 Mon Sep 17 00:00:00 2001 From: "John R. D'Orazio" Date: Sat, 18 Jul 2020 11:11:39 +0200 Subject: [PATCH 2/4] Fix _doing_it_wrong messages using sprintf give more info in the messages output by _doing_it_wrong by including route and namespace --- src/wp-includes/rest-api.php | 39 ++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index d6db464c0e..eaa9c3726b 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -37,10 +37,28 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f * 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.' ) . ' [Namespace = "' . $namespace . '", Route = "' . $route . '"]', '4.4.0' ); + _doing_it_wrong( + __FUNCTION__, + sprintf( + /* translators: %1$s: string value of the route, %2$s: string value of the namespace */ + __( 'Routes must be namespaced with plugin or theme name and version. Instead route %1$s seems to have empty namespace %2$s.' ), + ''.$namespace.'', + ''.$route.'' + ), + '4.4.0' + ); return false; } elseif ( empty( $route ) ) { - _doing_it_wrong( 'register_rest_route', __( 'Route must be specified.' ) . ' [Namespace = "' . $namespace . '", Route = "' . $route . '"]', '4.4.0' ); + _doing_it_wrong( + __FUNCTION__, + sprintf( + /* translators: %1$s: string value of the route, %2$s: string value of the namespace */ + __( 'Route must be specified. Instead there seems to be an empty route %1$s for the namespace %2$s.' ), + ''.$namespace.'', + ''.$route.'' + ), + '4.4.0' + ); return false; } @@ -49,16 +67,25 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f if ( $clean_namespace !== $namespace ) { _doing_it_wrong( __FUNCTION__, - __( 'Namespace must not start or end with a slash.' ) . ' [Namespace = "' . $namespace . '", Route = "' . $route . '"]', '5.4.2' ); + sprintf( + /* translators: %1$s: string value of the route, %2$s: string value of the namespace */ + __( 'Namespace must not start or end with a slash. Instead route %1$s has namespace %2$s.' ), + ''.$namespace.'', + ''.$route.'' + ), + '5.4.2' + ); } if ( ! did_action( 'rest_api_init' ) ) { _doing_it_wrong( __FUNCTION__, sprintf( - /* translators: %s: rest_api_init */ - __( 'REST API routes must be registered on the %s action.' ) . ' [Namespace = "' . $namespace . '", Route = "' . $route . '"]', - 'rest_api_init' + /* translators: %1$s: rest_api_init, %2$s: string value of the route, %3$s: 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', + ''.$namespace.'', + ''.$route.'' ), '5.1.0' ); From 28d04022aa2207c6fb2f1586637dcb4ad5beebaa Mon Sep 17 00:00:00 2001 From: "John R. D'Orazio" Date: Sat, 18 Jul 2020 11:16:18 +0200 Subject: [PATCH 3/4] fix association of sprintf variables --- src/wp-includes/rest-api.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index eaa9c3726b..527112c698 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -40,8 +40,8 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f _doing_it_wrong( __FUNCTION__, sprintf( - /* translators: %1$s: string value of the route, %2$s: string value of the namespace */ - __( 'Routes must be namespaced with plugin or theme name and version. Instead route %1$s seems to have empty namespace %2$s.' ), + /* translators: %1$s: string value of the namespace, %2$s: string value of the route */ + __( 'Routes must be namespaced with plugin or theme name and version. Instead route %2$s seems to have empty namespace %1$s.' ), ''.$namespace.'', ''.$route.'' ), @@ -52,8 +52,8 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f _doing_it_wrong( __FUNCTION__, sprintf( - /* translators: %1$s: string value of the route, %2$s: string value of the namespace */ - __( 'Route must be specified. Instead there seems to be an empty route %1$s for the namespace %2$s.' ), + /* translators: %1$s: string value of the namespace, %2$s: string value of the route */ + __( 'Route must be specified. Instead there seems to be an empty route %2$s for the namespace %1$s.' ), ''.$namespace.'', ''.$route.'' ), @@ -68,8 +68,8 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f _doing_it_wrong( __FUNCTION__, sprintf( - /* translators: %1$s: string value of the route, %2$s: string value of the namespace */ - __( 'Namespace must not start or end with a slash. Instead route %1$s has namespace %2$s.' ), + /* translators: %1$s: string value of the namespace, %2$s: string value of the route */ + __( 'Namespace must not start or end with a slash. Instead route %2$s has namespace %1$s.' ), ''.$namespace.'', ''.$route.'' ), @@ -81,8 +81,8 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f _doing_it_wrong( __FUNCTION__, sprintf( - /* translators: %1$s: rest_api_init, %2$s: string value of the route, %3$s: 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.' ), + /* translators: %1$s: rest_api_init, %2$s: string value of the namespace, %3$s: string value of the route */ + __( 'REST API routes must be registered on the %1$s action. Instead route %3$s with namespace %2$s was not registered on this action.' ), 'rest_api_init', ''.$namespace.'', ''.$route.'' From e5e6b5e8f96d4d7651fe582545b80e3f6051c84c Mon Sep 17 00:00:00 2001 From: "John R. D'Orazio" Date: Tue, 21 Jul 2020 10:21:21 +0200 Subject: [PATCH 4/4] Update rest-api.php change grammatical order of some messages --- src/wp-includes/rest-api.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 527112c698..9c10a8292a 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -41,7 +41,7 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f __FUNCTION__, sprintf( /* translators: %1$s: string value of the namespace, %2$s: string value of the route */ - __( 'Routes must be namespaced with plugin or theme name and version. Instead route %2$s seems to have empty namespace %1$s.' ), + __( '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\'.' ), ''.$namespace.'', ''.$route.'' ), @@ -53,7 +53,7 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f __FUNCTION__, sprintf( /* translators: %1$s: string value of the namespace, %2$s: string value of the route */ - __( 'Route must be specified. Instead there seems to be an empty route %2$s for the namespace %1$s.' ), + __( 'Route must be specified. Instead within the namespace \'%1$s\', there seems to be an empty route \'%2$s\'.' ), ''.$namespace.'', ''.$route.'' ), @@ -69,7 +69,7 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f __FUNCTION__, sprintf( /* translators: %1$s: string value of the namespace, %2$s: string value of the route */ - __( 'Namespace must not start or end with a slash. Instead route %2$s has namespace %1$s.' ), + __( 'Namespace must not start or end with a slash. Instead namespace \'%1$s\' for route \'%2$s\' seems to contain a slash.' ), ''.$namespace.'', ''.$route.'' ), @@ -82,7 +82,7 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f __FUNCTION__, sprintf( /* translators: %1$s: rest_api_init, %2$s: string value of the namespace, %3$s: string value of the route */ - __( 'REST API routes must be registered on the %1$s action. Instead route %3$s with namespace %2$s was not registered on this action.' ), + __( 'REST API routes must be registered on the %1$s action. Instead route \'%3$s\' with namespace \'%2$s\' was not registered on this action.' ), 'rest_api_init', ''.$namespace.'', ''.$route.''