fix(auth): logout without /logout rewrite (avoid Apache 404)

This commit is contained in:
2026-07-25 15:09:58 +08:00
parent 820fafd8a7
commit 6e71008d00
2 changed files with 54 additions and 8 deletions
+18 -3
View File
@@ -261,10 +261,25 @@ function aksrt_get_bind_url($transient_key = '') {
endif;
if (!function_exists('aksrt_get_logout_url')) :
/** 获取退出登录 URL */
/**
* 获取退出登录 URL。
*
* Prefer query-arg form so logout works even when /logout/ rewrite is missing
* (Apache would 404 the pretty path before WordPress runs). Pretty /logout/
* remains registered as a convenience alias.
*
* @param string $redirect Redirect after logout.
*/
function aksrt_get_logout_url($redirect = '') {
$target = $redirect ?: home_url('/');
$url = add_query_arg('redirect_to', rawurlencode($target), home_url('/logout/'));
$target = is_string($redirect) && $redirect !== '' ? $redirect : home_url('/');
// home_url('/?aksrt_logout=1') always hits index.php without rewrite rules.
$url = add_query_arg(
[
'aksrt_logout' => '1',
'redirect_to' => $target,
],
home_url('/')
);
return wp_nonce_url($url, 'aksrt-logout');
}
endif;