[wp-trac] [WordPress Trac] #49749: Bug in WordPress API when I have the prefix wp for the custom endpoint
WordPress Trac
noreply at wordpress.org
Thu Apr 2 16:10:02 UTC 2020
#49749: Bug in WordPress API when I have the prefix wp for the custom endpoint
-------------------------------------+-----------------------
Reporter: skarabeq | Owner: (none)
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 5.4.1
Component: REST API | Version: 5.4
Severity: normal | Resolution:
Keywords: needs-patch 2nd-opinion | Focuses:
-------------------------------------+-----------------------
Comment (by TimothyBlynJacobs):
It is not a workaround, a namespace with a prefixed slash is **not**
valid. It is able to serve the routes when you register your own namespace
with a prefixed slash because all the routes are belonging to the same
group. If you had registered both `/my-ns` and `my-ns` as a namespace
you'd have the same issue.
And, if you register that route, the index will not work for you.
{{{#!php
<?php
add_action('rest_api_init', function() {
register_rest_route(
'/lp/v2',
'/nav/',
array(
'methods' => 'GET',
'callback' => static function () {
return new WP_REST_Response( null, 204 );
},
)
);
});
}}}
{{{
curl https://trunk.test/wp-json/lp/v2/
{"code":"rest_no_route","message":"No route was found matching the URL and
request method","data":{"status":404}}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49749#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list