refactor(admin): consolidate duplicate configuration

Remove duplicate comment, captcha, filing, and website-security configuration paths.

Move front submission verification to the captcha scene matrix and retire obsolete admin routes and components.
This commit is contained in:
2026-08-13 02:26:17 +08:00
parent 0752a2fbf6
commit ab70a5eae9
32 changed files with 86 additions and 912 deletions
+8 -25
View File
@@ -39,6 +39,7 @@ function aksrt_captcha_scenes(): array {
'verify_email' => __('邮箱验证', 'aksrt'),
'download' => __('资源下载', 'aksrt'),
'signin' => __('每日签到', 'aksrt'),
'front_submit' => __('前台投稿', 'aksrt'),
];
}
@@ -46,14 +47,12 @@ function aksrt_captcha_scenes(): array {
* 默认配置结构。
*/
function aksrt_captcha_default_config(): array {
$all_scenes = array_keys(aksrt_captcha_scenes());
$default_scenes = array_values(array_diff(array_keys(aksrt_captcha_scenes()), ['front_submit']));
return [
'enabled' => false,
'active_provider' => '',
// Positive list: checked scenes require captcha. Default all scenes.
'enabled_scenarios' => $all_scenes,
// Legacy mirror kept for BC consumers / admin summaries.
'disabled_scenarios' => [],
// Positive list: checked scenes require captcha. Front submissions stay opt-in.
'enabled_scenarios' => $default_scenes,
'tencent' => [],
'aliyun' => [],
'cloudflare' => [],
@@ -85,32 +84,20 @@ function aksrt_captcha_sanitize_scene_list($raw): array {
* @return array
*/
function aksrt_get_captcha_config(): array {
$cfg = get_option('aksrt_captcha_config', []);
if (!is_array($cfg)) {
$cfg = [];
}
$stored = get_option('aksrt_captcha_config', []);
$cfg = array_merge(aksrt_captcha_default_config(), is_array($stored) ? $stored : []);
$all_scenes = array_keys(aksrt_captcha_scenes());
$provider = isset($cfg['active_provider']) ? sanitize_key((string) $cfg['active_provider']) : '';
if (!in_array($provider, aksrt_captcha_providers(), true)) {
$provider = '';
}
if (array_key_exists('enabled_scenarios', $cfg)) {
// Explicit positive list (may be empty = no scenes).
$enabled = aksrt_captcha_sanitize_scene_list($cfg['enabled_scenarios']);
} else {
// Legacy: only disabled list stored → all minus disabled.
$disabled_legacy = aksrt_captcha_sanitize_scene_list($cfg['disabled_scenarios'] ?? []);
$enabled = array_values(array_diff($all_scenes, $disabled_legacy));
}
$disabled = array_values(array_diff($all_scenes, $enabled));
$enabled = aksrt_captcha_sanitize_scene_list($cfg['enabled_scenarios'] ?? []);
$result = [
'enabled' => !empty($cfg['enabled']),
'active_provider' => $provider,
'enabled_scenarios' => $enabled,
'disabled_scenarios' => $disabled,
];
foreach (aksrt_captcha_providers() as $p) {
$result[$p] = isset($cfg[$p]) && is_array($cfg[$p]) ? $cfg[$p] : [];
@@ -174,11 +161,7 @@ function aksrt_is_captcha_enabled_for($scene): bool {
return false;
}
$enabled = isset($cfg['enabled_scenarios']) && is_array($cfg['enabled_scenarios'])
? $cfg['enabled_scenarios']
: array_values(array_diff(array_keys(aksrt_captcha_scenes()), (array) ($cfg['disabled_scenarios'] ?? [])));
return in_array($scene, $enabled, true);
return in_array($scene, $cfg['enabled_scenarios'], true);
}
/**