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:
@@ -25,9 +25,6 @@ add_filter('comments_open', function ($open, $post_id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!get_option('aksrt_comment_enabled', true)) {
|
||||
return false;
|
||||
}
|
||||
return $open;
|
||||
}, 10, 2);
|
||||
|
||||
|
||||
@@ -454,6 +454,19 @@ if (!function_exists('aksrt_comments_render_form')) :
|
||||
? sanitize_text_field(wp_unslash((string) $_COOKIE['comment_author_email_' . COOKIEHASH]))
|
||||
: '';
|
||||
$placeholder = (string) $ctx['box_placeholder'];
|
||||
$post_id = (int) get_the_ID();
|
||||
$can_comment = function_exists('aksrt_user_can')
|
||||
? aksrt_user_can('comment_add', get_current_user_id(), $post_id)
|
||||
: $is_logged_in;
|
||||
|
||||
if (!$can_comment) {
|
||||
if (!$is_logged_in) {
|
||||
aksrt_comments_render_signarea($ctx);
|
||||
} else {
|
||||
echo '<p class="comments-permission-denied muted-2-color">' . esc_html__('当前账号没有发表评论的权限。', 'aksrt') . '</p>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_get_comment_virtual_input_html')) {
|
||||
echo aksrt_get_comment_virtual_input_html($placeholder, '#respond'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
+8
-25
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user