From dc3f5a0cf5019ff2b78e875fbc3915195f66ec8c Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 4 Nov 2015 21:22:21 +0000 Subject: [PATCH] REST API: in `WP_REST_Server::dispatch()`, move `preg_match()` out of it's current loop, which doesn't affect the context passed to it. Props TobiasBg. Fixes #34488. git-svn-id: https://develop.svn.wordpress.org/trunk@35514 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/rest-api/class-wp-rest-server.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php index eae12544a6..1a239a596b 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -763,6 +763,12 @@ class WP_REST_Server { $path = $request->get_route(); foreach ( $this->get_routes() as $route => $handlers ) { + $match = preg_match( '@^' . $route . '$@i', $path, $args ); + + if ( ! $match ) { + continue; + } + foreach ( $handlers as $handler ) { $callback = $handler['callback']; $response = null; @@ -771,12 +777,6 @@ class WP_REST_Server { continue; } - $match = preg_match( '@^' . $route . '$@i', $path, $args ); - - if ( ! $match ) { - continue; - } - if ( ! is_callable( $callback ) ) { $response = new WP_Error( 'rest_invalid_handler', __( 'The handler for the route is invalid' ), array( 'status' => 500 ) ); }