[wp-trac] [WordPress Trac] #38873: REST API doesn't match with trailing slash when not using rewrites
WordPress Trac
noreply at wordpress.org
Mon Nov 21 09:45:12 UTC 2016
#38873: REST API doesn't match with trailing slash when not using rewrites
--------------------------+---------------------
Reporter: joehoyle | Owner: rmccue
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 4.7
Component: REST API | Version:
Severity: normal | Resolution: fixed
Keywords: has-patch | Focuses:
--------------------------+---------------------
Comment (by jnylen0):
This hack gets the API console working again on my test sites. I don't
think there would be any harm in removing leading slashes from the route
as well - it's apparently an easy place to make a mistake.
{{{#!php
$ cat wp-content/plugins/fix-rest-api-console.php
<?php
/**
* Plugin Name: Fix the REST API console (`wp-json//` → `wp-json/`)
* Author: James Nylen
* Plugin URI: https://core.trac.wordpress.org/ticket/38873
*/
add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) {
$route = $request->get_route();
$route_fixed = preg_replace( '@^/+@', '/', $route );
if ( $route_fixed !== $route ) {
$request->set_route( $route_fixed );
}
return $result;
}, 10, 3 );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38873#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list