Skip to content

Commit

Permalink
🚑 Fix responses always returning 200 on WordPress routes (Fixes #411)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Nov 6, 2024
1 parent b72fd72 commit a9c6fa0
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/Roots/Acorn/Application/Concerns/Bootable.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,19 @@ protected function registerRequestHandler(
$path = Str::finish($request->getBaseUrl(), $request->getPathInfo());

$except = collect([
rest_url(),
admin_url(),
wp_login_url(),
wp_registration_url(),
])->map(fn ($url) => parse_url($url, PHP_URL_PATH))->unique()->filter();

$api = parse_url(rest_url(), PHP_URL_PATH);

if (
Str::startsWith($path, $except->all()) ||
Str::endsWith($path, '.php')
) {
return;
}

if (
$isApi = Str::startsWith($path, $api) &&
redirect_canonical(null, false)
) {
return;
}

add_filter('do_parse_request', function ($condition, $wp, $params) use ($route) {
if (! $route) {
return $condition;
Expand All @@ -215,9 +207,11 @@ protected function registerRequestHandler(
return;
}

$config = $this->config->get('router.wordpress', ['web' => 'web', 'api' => 'api']);
if (redirect_canonical(null, false)) {
return;
}

$route->middleware($isApi ? $config['api'] : $config['web']);
$route->middleware('web');

ob_start();

Expand Down

0 comments on commit a9c6fa0

Please sign in to comment.