Skip to content

Commit dc3f5a0

Browse files
committed
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
1 parent eef98a3 commit dc3f5a0

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/wp-includes/rest-api/class-wp-rest-server.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,12 @@ public function dispatch( $request ) {
763763
$path = $request->get_route();
764764

765765
foreach ( $this->get_routes() as $route => $handlers ) {
766+
$match = preg_match( '@^' . $route . '$@i', $path, $args );
767+
768+
if ( ! $match ) {
769+
continue;
770+
}
771+
766772
foreach ( $handlers as $handler ) {
767773
$callback = $handler['callback'];
768774
$response = null;
@@ -771,12 +777,6 @@ public function dispatch( $request ) {
771777
continue;
772778
}
773779

774-
$match = preg_match( '@^' . $route . '$@i', $path, $args );
775-
776-
if ( ! $match ) {
777-
continue;
778-
}
779-
780780
if ( ! is_callable( $callback ) ) {
781781
$response = new WP_Error( 'rest_invalid_handler', __( 'The handler for the route is invalid' ), array( 'status' => 500 ) );
782782
}

0 commit comments

Comments
 (0)