Skip to content

Commit fa72c12

Browse files
committed
REST API: sub-requests must always use dispatch.
Props xknown, johnbillion, joehoyle, jorbin, sergeybiryukov, ehtis, desrosj. git-svn-id: https://develop.svn.wordpress.org/trunk@62769 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ee57cbd commit fa72c12

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/wp-includes/rest-api.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,15 @@ function rest_api_loaded() {
450450
return;
451451
}
452452

453+
// Short-circuit before define()/die() if a REST dispatch is already in flight.
454+
// serve_request() enforces this too; guarding here avoids the trailing die().
455+
if ( isset( $GLOBALS['wp_rest_server'] )
456+
&& $GLOBALS['wp_rest_server'] instanceof WP_REST_Server
457+
&& $GLOBALS['wp_rest_server']->is_dispatching()
458+
) {
459+
return;
460+
}
461+
453462
// Return an error message if query_var is not a string.
454463
if ( ! is_string( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
455464
$rest_type_error = new WP_Error(

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ protected function get_json_encode_options( WP_REST_Request $request ) {
283283
* @return null|false Null if not served and a HEAD request, false otherwise.
284284
*/
285285
public function serve_request( $path = null ) {
286+
// Refuse to start a fresh top-level REST cycle while another dispatch
287+
// is already in flight. Internal sub-requests must use dispatch().
288+
if ( $this->is_dispatching() ) {
289+
return false;
290+
}
291+
286292
/* @var WP_User|null $current_user */
287293
global $current_user;
288294

0 commit comments

Comments
 (0)