[wp-trac] [WordPress Trac] #49749: Bug in WordPress API when I have the prefix wp for the custom endpoint (was: Registering rest routes with a slash-prefixed namespace give inconsistent results)
WordPress Trac
noreply at wordpress.org
Thu Apr 2 16:40:13 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 skarabeq):
@TimothyBlynJacobs, Ok, I agree that in the world of the WordPress the
route with slash is **not** valid.. But I can't understand that because
the namespace of route with slash and the namespace of the route without
slash should be same. If someone make two routes with the same namespace
and endpoint, then he is made something wrongly. You can get best practice
in the one of the best PHP frameworks - Laravel - Routing -
[https://laravel.com/docs/7.x/routing].
One of the best pattern of the grouping routes is like this:
{{{#!php
<?php
Route::prefix('admin')->group(function () {
Route::get('navigation', function () {
// Matches The "/admin/navigation" URL
return AdminModelNavigation::getAll();
});
Route::get('users', function () {
// Matches The "/admin/users" URL
return AdminModelUsers::getAll();
});
});
}}}
But, WordPress is far, far away from this path. So do the best, and if you
fix the problem that I meet I will be very happy :)
Kind regards,
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49749#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list