Skip to content

Commit

Permalink
conditionally add middleware for wp-json api
Browse files Browse the repository at this point in the history
  • Loading branch information
broskees committed Jan 26, 2024
1 parent e6ccc87 commit d11c068
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Roots/Acorn/Bootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ protected function bootHttp(ApplicationContract $app)
$app->make('router')
->any('{any?}', fn () => ob_get_clean())
->where('any', '.*')
->middleware($app->config->get('routing.wordpress', 'web'))
->name('wordpress_request');

/** @var \Illuminate\Routing\Route $route */
Expand All @@ -225,12 +224,19 @@ protected function bootHttp(ApplicationContract $app)
}, 100, 3);

if ($isWPRequest = $route->getName() === 'wordpress_request') {
$route->middleware(
str_starts_with($request->path(), 'wp-json')
? $app->config->get('router.wordpress.api', 'api')
: $app->config->get('router.wordpress.web', 'web')
);

ob_start();
}

add_action(
$isWPRequest ? 'shutdown' : 'parse_request',
fn () => $this->handleRequest($kernel, $request)
fn () => $this->handleRequest($kernel, $request),
$isWPRequest ? PHP_INT_MAX : 10
);
}

Expand Down

0 comments on commit d11c068

Please sign in to comment.