登录注册体系的源码级硬切换
This commit is contained in:
1 parent
73fcd4ed72
commit
af52f9e94d
72 files changed
+1666
-6576
No files matched your search
@@ -11,58 +11,7 @@ defined('ABSPATH') || exit;
|
||||
// 一、模板注册表 — 所有特殊页面的"身份证"
|
||||
// 修改此处即可增删模板页面,无需改动其他逻辑
|
||||
// ============================================================
|
||||
$_aksrt_special_templates = [
|
||||
'login' => [
|
||||
'file' => 'templates/pages/page-login.php',
|
||||
'slug' => 'login',
|
||||
'title' => '登录',
|
||||
'fallback' => '/login/',
|
||||
],
|
||||
'register' => [
|
||||
'file' => 'templates/pages/page-register.php',
|
||||
'slug' => 'register',
|
||||
'title' => '注册',
|
||||
'fallback' => '/register/',
|
||||
],
|
||||
'bind' => [
|
||||
'file' => 'templates/pages/page-bind-account.php',
|
||||
'slug' => 'bind-account',
|
||||
'title' => '绑定账号',
|
||||
'fallback' => '/bind-account/',
|
||||
],
|
||||
'reset-password' => [
|
||||
'file' => 'templates/pages/page-reset-password.php',
|
||||
'slug' => 'reset-password',
|
||||
'title' => '重置密码',
|
||||
'fallback' => '/reset-password/',
|
||||
],
|
||||
'verify-email' => [
|
||||
'file' => 'templates/pages/page-verify-email.php',
|
||||
'slug' => 'verify-email',
|
||||
'title' => '邮箱验证',
|
||||
'fallback' => '/verify-email/',
|
||||
],
|
||||
'categories' => [
|
||||
'file' => 'templates/pages/page-categories.php',
|
||||
'slug' => 'categories',
|
||||
'title' => '分类目录',
|
||||
'fallback' => '/categories/',
|
||||
],
|
||||
'friends' => [
|
||||
'file' => 'templates/pages/page-friends.php',
|
||||
'slug' => 'friends',
|
||||
'title' => '友情链接',
|
||||
'fallback' => '/friends/',
|
||||
],
|
||||
'profile' => [
|
||||
'file' => 'templates/pages/page-profile.php',
|
||||
'slug' => 'profile',
|
||||
'title' => '个人中心',
|
||||
'fallback' => '/',
|
||||
],
|
||||
];
|
||||
|
||||
// legacy-style v2 routing keeps only true fixed template pages in the registry.
|
||||
// Only true fixed template pages live in the registry.
|
||||
$_aksrt_special_templates = [
|
||||
'sign' => [
|
||||
'file' => 'templates/pages/page-sign.php',
|
||||
@@ -70,24 +19,6 @@ $_aksrt_special_templates = [
|
||||
'title' => '登录/注册',
|
||||
'fallback' => '/sign/',
|
||||
],
|
||||
'bind' => [
|
||||
'file' => 'templates/pages/page-bind-account.php',
|
||||
'slug' => 'bind-account',
|
||||
'title' => '绑定账号',
|
||||
'fallback' => '/bind-account/',
|
||||
],
|
||||
'reset-password' => [
|
||||
'file' => 'templates/pages/page-reset-password.php',
|
||||
'slug' => 'reset-password',
|
||||
'title' => '重置密码',
|
||||
'fallback' => '/reset-password/',
|
||||
],
|
||||
'verify-email' => [
|
||||
'file' => 'templates/pages/page-verify-email.php',
|
||||
'slug' => 'verify-email',
|
||||
'title' => '邮箱验证',
|
||||
'fallback' => '/verify-email/',
|
||||
],
|
||||
'categories' => [
|
||||
'file' => 'templates/pages/page-categories.php',
|
||||
'slug' => 'categories',
|
||||
@@ -203,21 +134,9 @@ function aksrt_resolve_page_template_file(string $template_file = '', string $po
|
||||
$template_file = ltrim($template_file, '/\\');
|
||||
$post_slug = sanitize_title($post_slug);
|
||||
|
||||
$legacy_auth_templates = [
|
||||
'templates/pages/page-login.php' => 'login',
|
||||
'templates/pages/page-register.php' => 'register',
|
||||
'templates/pages/page-bind-account.php' => 'bind',
|
||||
'templates/pages/page-reset-password.php' => 'reset-password',
|
||||
'templates/pages/page-verify-email.php' => 'verify-email',
|
||||
];
|
||||
|
||||
if ($template_file !== '') {
|
||||
if ($template_file === 'templates/pages/page-sign.php') {
|
||||
return aksrt_get_auth_template_file(aksrt_get_auth_tab(), true);
|
||||
}
|
||||
|
||||
if (!empty($legacy_auth_templates[$template_file])) {
|
||||
return aksrt_get_auth_template_file((string) $legacy_auth_templates[$template_file], true);
|
||||
return $template_file;
|
||||
}
|
||||
|
||||
if (strpos($template_file, 'templates/pages/') === 0 && aksrt_locate_template_file($template_file)) {
|
||||
@@ -226,17 +145,8 @@ function aksrt_resolve_page_template_file(string $template_file = '', string $po
|
||||
}
|
||||
|
||||
if ($post_slug !== '') {
|
||||
$auth_slug_map = [
|
||||
'sign' => aksrt_get_auth_tab(),
|
||||
'login' => 'login',
|
||||
'register' => 'register',
|
||||
'bind-account' => 'bind',
|
||||
'reset-password' => 'reset-password',
|
||||
'verify-email' => 'verify-email',
|
||||
];
|
||||
|
||||
if (!empty($auth_slug_map[$post_slug])) {
|
||||
return aksrt_get_auth_template_file((string) $auth_slug_map[$post_slug], true);
|
||||
if ($post_slug === 'sign') {
|
||||
return 'templates/pages/page-sign.php';
|
||||
}
|
||||
|
||||
$slug_map = [
|
||||
@@ -261,87 +171,20 @@ function aksrt_normalize_auth_tab(string $tab): string {
|
||||
|
||||
switch ($tab) {
|
||||
case 'signin':
|
||||
case 'login':
|
||||
return 'login';
|
||||
return 'signin';
|
||||
case 'signup':
|
||||
case 'register':
|
||||
return 'register';
|
||||
return 'signup';
|
||||
case 'bind':
|
||||
case 'bind-account':
|
||||
return 'bind';
|
||||
case 'reset':
|
||||
case 'lostpassword':
|
||||
case 'reset-password':
|
||||
return 'reset-password';
|
||||
case 'verify':
|
||||
case 'verify-email':
|
||||
return 'verify-email';
|
||||
case 'resetpassword':
|
||||
return 'resetpassword';
|
||||
case 'oauth':
|
||||
return 'oauth';
|
||||
default:
|
||||
return 'login';
|
||||
return 'signin';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an auth tab should be rendered by the unified sign page.
|
||||
*/
|
||||
function aksrt_auth_tab_uses_unified_sign_page(string $tab): bool {
|
||||
return in_array(
|
||||
aksrt_normalize_auth_tab($tab),
|
||||
['login', 'register'],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the auth template file, preferring the unified sign page when present.
|
||||
*/
|
||||
function aksrt_get_auth_template_file(string $tab = 'login', bool $prefer_sign_page = true): string {
|
||||
$normalized_tab = aksrt_normalize_auth_tab($tab);
|
||||
$sign_template = 'templates/pages/page-sign.php';
|
||||
|
||||
if (
|
||||
$prefer_sign_page
|
||||
&& aksrt_auth_tab_uses_unified_sign_page($normalized_tab)
|
||||
&& aksrt_locate_template_file($sign_template)
|
||||
) {
|
||||
return $sign_template;
|
||||
}
|
||||
|
||||
switch ($normalized_tab) {
|
||||
case 'register':
|
||||
return 'templates/pages/page-register.php';
|
||||
case 'bind':
|
||||
return 'templates/pages/page-bind-account.php';
|
||||
case 'reset-password':
|
||||
return 'templates/pages/page-reset-password.php';
|
||||
case 'verify-email':
|
||||
return 'templates/pages/page-verify-email.php';
|
||||
default:
|
||||
return 'templates/pages/page-login.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the active auth view for sign routes and the sign page template.
|
||||
*/
|
||||
function aksrt_get_auth_tab(): string {
|
||||
$query_tab = get_query_var('aksrt_auth_tab');
|
||||
if (is_string($query_tab) && $query_tab !== '') {
|
||||
return aksrt_normalize_auth_tab($query_tab);
|
||||
}
|
||||
|
||||
if (!empty($_GET['tab'])) {
|
||||
return aksrt_normalize_auth_tab((string) wp_unslash($_GET['tab']));
|
||||
}
|
||||
|
||||
$post = get_queried_object();
|
||||
if ($post instanceof WP_Post) {
|
||||
return aksrt_normalize_auth_tab((string) $post->post_name);
|
||||
}
|
||||
|
||||
return 'login';
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除模板页面缓存
|
||||
*/
|
||||
@@ -389,9 +232,8 @@ function aksrt_get_current_special_template_path(): string {
|
||||
return $profile_template ?: '';
|
||||
}
|
||||
|
||||
if (get_query_var('aksrt_sign')) {
|
||||
$auth_template = aksrt_get_auth_template_file((string) get_query_var('aksrt_auth_tab'), true);
|
||||
$auth_template_path = aksrt_locate_template_file($auth_template);
|
||||
if (get_query_var('aksrt_sign')) {
|
||||
$auth_template_path = aksrt_locate_template_file('templates/pages/page-sign.php');
|
||||
return $auth_template_path ?: '';
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user