登录注册体系的源码级硬切换

This commit is contained in:
kate522 committed 2026-08-23 20:30:01 +08:00
1 parent 73fcd4ed72
commit af52f9e94d
72 files changed
+1666 -6576

No files matched your search

+86 -74
View File
@@ -15,41 +15,9 @@ trait AuthReader {
return !class_exists(Capabilities::class) || !Capabilities::user_can('comment_add', $user_id);
}
/** 是否允许注册 */
/** 是否允许前台注册。主题设置是唯一真值。 */
public static function registration_enabled(): bool {
return (bool) get_option('users_can_register');
}
/** 注册是否要求邮箱验证 */
public static function registration_requires_email_verification(): bool {
$s = self::get_all();
return self::registration_enabled() && !empty($s['registration_email_verification_enabled']);
}
/** 注册邮箱验证方式 */
public static function registration_verification_method(): string {
$s = self::get_all();
$method = $s['registration_email_verification_method'] ?? 'link';
return in_array($method, ['link', 'code'], true) ? $method : 'link';
}
/** 注册邮箱验证有效期(分钟) */
public static function registration_verification_ttl_minutes(): int {
$s = self::get_all();
$ttl = (int) ($s['registration_verification_ttl_minutes'] ?? 30);
return max(5, min(1440, $ttl));
}
/** 验证成功后自动登录 */
public static function registration_auto_login_after_verify(): bool {
$s = self::get_all();
return !isset($s['registration_auto_login_after_verify']) || !empty($s['registration_auto_login_after_verify']);
}
/** 注册邮箱验证功能首次启用时间戳(用于历史账号判定) */
public static function registration_verification_enabled_at(): int {
$s = self::get_all();
return (int) ($s['registration_verification_enabled_at'] ?? 0);
return !self::close_signup();
}
/** 主题内置默认图片 URL */
@@ -57,21 +25,15 @@ trait AuthReader {
return get_template_directory_uri() . '/assets/img/' . $filename;
}
/** 获取Logo URL(留空时使用内置默认;legacy别名 logo_src 回退) */
/** 获取 Logo URL(留空时使用内置默认) */
public static function logo_url(): string {
$url = trim((string) self::get_value('site_logo', ''));
if ($url === '') {
$url = trim((string) get_option('logo_src', ''));
}
return $url !== '' ? $url : self::default_asset_url('default-logo.svg');
}
/** 获取暗色模式 Logo URL(留空时跟随浅色模式;legacy别名 logo_src_dark 回退) */
/** 获取暗色模式 Logo URL(留空时跟随浅色模式) */
public static function logo_dark_url(): string {
$url = trim((string) self::get_value('site_logo_dark', ''));
if ($url === '') {
$url = trim((string) get_option('logo_src_dark', ''));
}
return $url !== '' ? $url : self::logo_url();
}
@@ -88,10 +50,10 @@ trait AuthReader {
return (bool) self::get_value('close_sign', false);
}
/** 是否关闭注册(受 close_sign 总开关影响;兼容 user_close_signup 别名) */
/** 是否关闭注册。禁用账密登录时同时关闭账密注册。 */
public static function close_signup(): bool {
if (self::close_sign()) return true;
return (bool) self::get_value('user_close_signup', false);
return (bool) self::get_value('close_signup', false) || self::close_signin();
}
/** 是否关闭账密登录(仅允许社交登录) */
@@ -100,16 +62,10 @@ trait AuthReader {
return (bool) self::get_value('close_signin', false);
}
/** 是否关闭登录(受 close_sign 总开关影响;兼容 user_close_login 别名) */
public static function close_login(): bool {
if (self::close_sign()) return true;
return (bool) self::get_value('user_close_login', false);
}
/** 登录注册样式: 'modal' | 'page'(默认 page;modal 运行时未就绪时自动回退 page) */
/** 登录注册样式: modal | page。 */
public static function user_sign_type(): string {
$type = (string) self::get_value('user_sign_type', 'page');
if (!in_array($type, ['modal', 'page'], true)) $type = 'page';
$type = (string) self::get_value('user_sign_type', 'modal');
if (!in_array($type, ['modal', 'page'], true)) $type = 'modal';
return $type;
}
@@ -118,16 +74,24 @@ trait AuthReader {
return trim((string) self::get_value('admin_sign_key', ''));
}
/** Whether wp-login.php is replaced by /sign/. */
public static function replace_wp_login(): bool {
return (bool) self::get_value('replace_wp_login', true);
}
/** 登录页 UI 配置数组 */
public static function sign_page_ui(): array {
$theme_mode = (string) self::get_value('sign_theme_mode', 'no');
if (!in_array($theme_mode, ['no', 'white-theme', 'dark-theme'], true)) {
$theme_mode = 'no';
}
return [
'background' => self::get_value('sign_page_background', []),
'theme_mode' => in_array((string) self::get_value('sign_theme_mode', 'default'), ['default', 'light', 'dark'], true)
? (string) self::get_value('sign_theme_mode', 'default') : 'default',
'theme_mode' => $theme_mode,
'show_header' => (bool) self::get_value('sign_show_header', true),
'card_position' => in_array((string) self::get_value('sign_card_position', 'center'), ['left', 'center', 'right'], true)
? (string) self::get_value('sign_card_position', 'center') : 'center',
'show_logo' => (bool) self::get_value('sign_show_logo', true),
'card_position' => in_array((string) self::get_value('sign_card_position', 'right'), ['left', 'center', 'right'], true)
? (string) self::get_value('sign_card_position', 'right') : 'right',
'show_logo' => (bool) self::get_value('sign_show_logo', false),
'footer' => (string) self::get_value('sign_page_footer', ''),
];
}
@@ -136,7 +100,7 @@ trait AuthReader {
public static function modal_ui(): array {
return [
'background' => self::get_value('sign_modal_background', []),
'show_logo' => (bool) self::get_value('sign_modal_show_logo', true),
'show_logo' => (bool) self::get_value('sign_modal_show_logo', false),
];
}
@@ -165,24 +129,70 @@ trait AuthReader {
return (bool) self::get_value('user_signin_phone_s', false);
}
/** 免密登录显示模式 */
public static function nopas_active_mode(): string {
$mode = (string) self::get_value('user_signin_nopas_active', 'nopas_first');
return in_array($mode, ['nopas_first', 'password_first', 'nopas_only'], true) ? $mode : 'nopas_first';
/** 是否启用验证码免密登录。 */
public static function passwordless_login_enabled(): bool {
return (bool) self::get_value('user_signin_nopas_s', false);
}
/** 绑定提醒类型(兼容旧 bool 值:true→'phone',false→'close') */
/** 免密登录验证渠道。 */
public static function passwordless_login_type(): string {
$type = (string) self::get_value('user_signin_nopas_type', 'email');
return in_array($type, ['email', 'phone', 'email_phone'], true) ? $type : 'email';
}
/** 免密登录显示模式 */
public static function nopas_active_mode(): string {
$mode = (string) self::get_value('user_signin_nopas_active', 'nopas');
return in_array($mode, ['nopas', 'pas', 'only_nopas'], true) ? $mode : 'nopas';
}
/** 是否在注册前验证邮箱或手机号。 */
public static function signup_verification_enabled(): bool {
return (bool) self::get_value('user_signup_captch', false);
}
/** 注册验证渠道。 */
public static function signup_verification_type(): string {
$type = (string) self::get_value('captch_type', 'email');
return in_array($type, ['email', 'phone', 'email_phone'], true) ? $type : 'email';
}
/** 找回密码验证渠道。 */
public static function reset_password_verification_type(): string {
$type = (string) self::get_value('user_repas_captch_type', 'email');
return in_array($type, ['email', 'phone', 'email_phone'], true) ? $type : 'email';
}
/** 注册时是否省略重复密码。 */
public static function signup_omit_password_confirmation(): bool {
return (bool) self::get_value('user_signup_no_repas', true);
}
/** 推广码在注册表单中的唯一显示模式。 */
public static function invitation_mode(): string {
$mode = (string) self::get_value('invit_code_s', 'close');
return in_array($mode, ['close', 'open', 'must'], true) ? $mode : 'close';
}
/** 自动弹窗配置。 */
public static function sign_modal_auto(): array {
return [
'enabled' => self::user_sign_type() === 'modal' && (bool) self::get_value('sign_modal_auto_s', false),
'waiting' => max(1, min(100, (int) self::get_value('sign_modal_auto_waiting_time', 5))),
'expires' => max(0, min(2000, (float) self::get_value('sign_modal_auto_expires', 1))),
];
}
/** 绑定提醒类型 */
public static function bind_reminder_type(): string {
$val = self::get_value('bind_reminder', 'close');
if (is_bool($val)) return $val ? 'phone' : 'close';
$val = (string) $val;
return in_array($val, ['email', 'phone', 'email_phone', 'close'], true) ? $val : 'close';
}
/** 强制绑定类型(兼容旧 bool 值:true→'phone',false→'close') */
/** 强制绑定类型 */
public static function mandatory_bind_type(): string {
$val = self::get_value('mandatory_bind', 'close');
if (is_bool($val)) return $val ? 'phone' : 'close';
$val = (string) $val;
return in_array($val, ['email', 'phone', 'email_phone', 'close'], true) ? $val : 'close';
}
@@ -196,10 +206,10 @@ trait AuthReader {
return array_values(array_filter(array_map('trim', $items), 'strlen'));
}
/** 邮箱限制配置:['type' => 'black'|'white', 'domains' => [...]] */
/** 邮箱限制配置:['type' => 'not'|'allow', 'domains' => [...]] */
public static function email_limit(): array {
$type = (string) self::get_value('user_email_limit_type', 'black');
if (!in_array($type, ['black', 'white'], true)) $type = 'black';
$type = (string) self::get_value('user_email_limit_type', 'not');
if (!in_array($type, ['not', 'allow'], true)) $type = 'not';
$raw = (string) self::get_value('user_email_out', '');
$domains = [];
if ($raw !== '') {
@@ -210,12 +220,14 @@ trait AuthReader {
}
/** 用户协议前台配置(enabled / required / page) */
/** 用户协议及隐私协议前台配置。 */
public static function user_agreement_settings(): array {
return [
'enabled' => !isset(self::get_all()['user_agreement_s']) || !empty(self::get_value('user_agreement_s', true)),
'required' => !isset(self::get_all()['user_agreement_check']) || !empty(self::get_value('user_agreement_check', true)),
'page' => trim((string) self::get_value('user_agreement_page', '')),
'enabled' => (bool) self::get_value('user_agreement_s', false),
'privacy' => (bool) self::get_value('user_privacy_s', false),
'required' => (bool) self::get_value('user_agreement_check', false),
'page' => trim((string) self::get_value('user_agreement_page', '')),
'privacy_page'=> trim((string) self::get_value('user_privacy_page', '')),
];
}
}