Make WordPress Core

Ticket #50493: register_rest_route_4.patch.txt

File register_rest_route_4.patch.txt, 2.7 KB (added by Lwangaman, 20 months ago)

resync with upstream

Line 
1diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
2index 7aa2534520..1c0a46fd2d 100644
3--- a/src/wp-includes/rest-api.php
4+++ b/src/wp-includes/rest-api.php
5@@ -38,26 +38,55 @@ function register_rest_route( $route_namespace, $route, $args = array(), $overri
6                 * and namespace indexes. If you really need to register a
7                 * non-namespaced route, call `WP_REST_Server::register_route` directly.
8                 */
9-               _doing_it_wrong( 'register_rest_route', __( 'Routes must be namespaced with plugin or theme name and version.' ), '4.4.0' );
10+               _doing_it_wrong(
11+                       __FUNCTION__,
12+                       sprintf(
13+                               /* translators: 1: string value of the namespace, 2: string value of the route. */
14+                               __( '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\'.' ),
15+                               '<code>' . $route_namespace . '</code>',
16+                               '<code>' . $route . '</code>'
17+                       ),
18+                       '4.4.0'
19+               );
20                return false;
21        } elseif ( empty( $route ) ) {
22-               _doing_it_wrong( 'register_rest_route', __( 'Route must be specified.' ), '4.4.0' );
23+               _doing_it_wrong(
24+                       __FUNCTION__,
25+                       sprintf(
26+                               /* translators: 1: string value of the namespace, 2: string value of the route. */
27+                               __( 'Route must be specified. Instead within the namespace \'%1$s\', there seems to be an empty route \'%2$s\'.' ),
28+                               '<code>' . $route_namespace . '</code>',
29+                               '<code>' . $route . '</code>'
30+                       ),
31+                       '4.4.0'
32+               );
33                return false;
34        }
35 
36        $clean_namespace = trim( $route_namespace, '/' );
37 
38        if ( $clean_namespace !== $route_namespace ) {
39-               _doing_it_wrong( __FUNCTION__, __( 'Namespace must not start or end with a slash.' ), '5.4.2' );
40+               _doing_it_wrong(
41+                       __FUNCTION__,
42+                       sprintf(
43+                               /* translators: 1: string value of the namespace, 2: string value of the route. */
44+                               __( 'Namespace must not start or end with a slash. Instead namespace \'%1$s\' for route \'%2$s\' seems to contain a slash.' ),
45+                               '<code>' . $route_namespace . '</code>',
46+                               '<code>' . $route . '</code>'
47+                       ),
48+                       '5.4.2'
49+               );
50        }
51 
52        if ( ! did_action( 'rest_api_init' ) ) {
53                _doing_it_wrong(
54-                       'register_rest_route',
55+                       __FUNCTION__,
56                        sprintf(
57-                               /* translators: %s: rest_api_init */
58-                               __( 'REST API routes must be registered on the %s action.' ),
59-                               '<code>rest_api_init</code>'
60+                               /* translators: 1: rest_api_init, 2: string value of the namespace, 3: string value of the route. */
61+                               __( '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.' ),
62+                               '<code>rest_api_init</code>',
63+                               '<code>' . $route_namespace . '</code>',
64+                               '<code>' . $route . '</code>'
65                        ),
66                        '5.1.0'
67                );