fix(admin): replicate reference comment settings page 1:1
- Rewrite post_list/comment schema (PHP + JS) with the reference theme's field set, order, defaults and dependencies; smilie, comment location and quick-reply fields excluded - Map PostDisplay::get_comment_display_settings() to the new keys without legacy fallback: close_comments, comment_paginate_type (ajax_lists), user_edit_comment master switch, WP comment_order for sorting - Wire comment_box_hide visibility gate (signin / vip / vip_2 / auth) - Drop dead comment settings (order/per_page/depth/avatar/hot threshold/ empty text/city), the dead post_close_comments field, and city readers now fully owned by the IP-geo extension - Add comment settings reference contract test
This commit is contained in:
@@ -136,7 +136,6 @@ class SchemaPostList {
|
||||
['key' => 'post_default_likes_min', 'label' => '默认点赞最小值', 'type' => 'number', 'default' => 5, 'min' => 0, 'max' => 9999],
|
||||
['key' => 'post_default_likes_max', 'label' => '默认点赞最大值', 'type' => 'number', 'default' => 15, 'min' => 1, 'max' => 9999],
|
||||
['key' => 'post_views_s', 'label' => '浏览统计', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'post_close_comments', 'label' => '关闭评论', 'type' => 'switch', 'default' => false],
|
||||
]],
|
||||
],
|
||||
],
|
||||
@@ -199,53 +198,36 @@ class SchemaPostList {
|
||||
'comment' => [
|
||||
'key' => 'comment',
|
||||
'title' => '评论设置',
|
||||
'version' => '1.0.0',
|
||||
'version' => '2.0.0',
|
||||
'option_key' => 'aksrt_settings',
|
||||
'groups' => [
|
||||
['key' => 'display', 'title' => '评论展示', 'fields' => [
|
||||
['key' => 'comment_order', 'label' => '评论排序', 'type' => 'radio', 'default' => 'asc', 'options' => [
|
||||
['label' => '正序', 'value' => 'asc'],
|
||||
['label' => '倒序', 'value' => 'desc'],
|
||||
['key' => 'comment', 'title' => '评论设置', 'fields' => [
|
||||
['key' => 'close_comments', 'label' => '关闭文章评论功能', 'type' => 'switcher', 'default' => false, 'description' => '部分网站无需交互,或需备案审核,可在此关闭所有文章的评论功能。同时每一篇文章可单独关闭评论功能'],
|
||||
['key' => 'comment_box_hide', 'label' => '隐藏评论模块', 'type' => 'radio', 'default' => '', 'dependsOn' => ['key' => 'close_comments', 'value' => false], 'options' => [
|
||||
['label' => '不隐藏', 'value' => ''],
|
||||
['label' => '登录后显示', 'value' => 'signin'],
|
||||
['label' => '所有会员显示', 'value' => 'vip'],
|
||||
['label' => '二级会员显示', 'value' => 'vip_2'],
|
||||
['label' => '认证用户显示', 'value' => 'auth'],
|
||||
], 'description' => '当用户满足条件时,文章评论功能及模块才会显示'],
|
||||
['key' => 'comment_paginate_type', 'label' => '评论列表翻页模式', 'type' => 'radio', 'default' => 'default', 'dependsOn' => ['key' => 'close_comments', 'value' => false], 'options' => [
|
||||
['label' => 'AJAX追加列表翻页', 'value' => 'ajax_lists'],
|
||||
['label' => '数字翻页按钮', 'value' => 'default'],
|
||||
]],
|
||||
['key' => 'comment_per_page', 'label' => '每页评论数', 'type' => 'number', 'default' => 20, 'min' => 5, 'max' => 100],
|
||||
['key' => 'comment_pagination_type', 'label' => '分页方式', 'type' => 'radio', 'default' => 'numbered', 'options' => [
|
||||
['label' => '翻页', 'value' => 'numbered'],
|
||||
['label' => '加载更多', 'value' => 'load_more'],
|
||||
['label' => '无限滚动', 'value' => 'infinite'],
|
||||
]],
|
||||
['key' => 'comment_paging_ajax_ias_s', 'label' => '评论自动加载', 'type' => 'switch', 'default' => true, 'description' => '评论无限滚动时自动触发加载'],
|
||||
['key' => 'comment_paging_ajax_ias_max', 'label' => '评论最大加载页数', 'type' => 'number', 'default' => 3, 'min' => 0, 'max' => 10, 'description' => '0=不限'],
|
||||
['key' => 'comment_nested_depth', 'label' => '回复嵌套深度', 'type' => 'number', 'default' => 3, 'min' => 1, 'max' => 10],
|
||||
['key' => 'comment_avatar_size', 'label' => '头像大小', 'type' => 'number', 'default' => 48, 'min' => 24, 'max' => 96],
|
||||
]],
|
||||
['key' => 'permissions', 'title' => '评论权限', 'fields' => [
|
||||
['key' => 'comment_close_comments', 'label' => '关闭评论', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'comment_edit_window', 'label' => '作者自助编辑时限(分钟)', 'type' => 'number', 'default' => 10, 'min' => 0, 'max' => 1440],
|
||||
]],
|
||||
['key' => 'toolbar', 'title' => '评论工具栏', 'fields' => [
|
||||
['key' => 'comment_code', 'label' => '代码插入', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_img', 'label' => '图片按钮', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_upload_img', 'label' => '评论图片上传', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'comment_link', 'label' => '链接按钮', 'type' => 'switch', 'default' => false],
|
||||
]],
|
||||
['key' => 'interaction', 'title' => '互动功能', 'fields' => [
|
||||
['key' => 'comment_hot_threshold', 'label' => '神评点赞阈值', 'type' => 'number', 'default' => 10, 'min' => 1, 'max' => 999],
|
||||
['key' => 'comment_like_s', 'label' => '评论点赞', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_user_url_s', 'label' => '匿名者网址', 'type' => 'switch', 'default' => false, 'description' => '用户未登录评论时,允许输入用户博客地址'],
|
||||
['key' => 'comment_city_s', 'label' => '评论城市', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_city_type', 'label' => '城市显示格式', 'type' => 'radio', 'default' => 'province_city', 'options' => [
|
||||
['label' => '省份+城市', 'value' => 'province_city'],
|
||||
['label' => '仅省份', 'value' => 'province'],
|
||||
['label' => '国家+省份', 'value' => 'country_province'],
|
||||
]],
|
||||
['key' => 'comment_author_tag', 'label' => '作者标签', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_corderby', 'label' => '评论排序切换', 'type' => 'switch', 'default' => true, 'description' => '前台显示最新/最早/最热切换按钮'],
|
||||
]],
|
||||
['key' => 'text', 'title' => '文案配置', 'fields' => [
|
||||
['key' => 'comment_empty_text', 'label' => '空评论提示', 'type' => 'input', 'default' => '暂无评论,来做第一个评论的人吧~'],
|
||||
['key' => 'comment_title', 'label' => '评论区标题', 'type' => 'input', 'default' => '评论'],
|
||||
['key' => 'comment_submit_text', 'label' => '提交按钮文案', 'type' => 'input', 'default' => '提交评论'],
|
||||
['key' => 'comment_text', 'label' => '评论框提示', 'type' => 'input', 'default' => '说点什么吧...'],
|
||||
['key' => 'comment_paging_ajax_ias_s', 'label' => 'AJAX翻页自动加载', 'type' => 'switcher', 'default' => true, 'dependsOn' => ['key' => 'comment_paginate_type', 'value' => 'ajax_lists'], 'description' => '页面滚动到列表尽头时,自动加载下一页'],
|
||||
['key' => 'comment_paging_ajax_ias_max', 'label' => '自动加载页数', 'type' => 'number', 'default' => 3, 'min' => 0, 'max' => 10, 'unit' => '页', 'dependsOn' => ['all' => [['key' => 'comment_paginate_type', 'value' => 'ajax_lists'], ['key' => 'comment_paging_ajax_ias_s', 'value' => true]]], 'description' => 'AJAX翻页自动加载最多加载几页(为0则不限制,直到加载全部评论)'],
|
||||
['key' => 'comment_code', 'label' => '允许插入代码', 'type' => 'switcher', 'default' => true, 'dependsOn' => ['key' => 'close_comments', 'value' => false], 'help' => '为了防止恶意评论,建议在后台-设置-讨论:开启“用户必须登录后才能发表评论”'],
|
||||
['key' => 'comment_img', 'label' => '允许插入图片', 'type' => 'switcher', 'default' => true, 'dependsOn' => ['key' => 'close_comments', 'value' => false]],
|
||||
['key' => 'comment_upload_img', 'label' => '允许上传图片', 'type' => 'switcher', 'default' => false, 'dependsOn' => ['all' => [['key' => 'close_comments', 'value' => false], ['key' => 'comment_img', 'value' => true]]]],
|
||||
['key' => 'comment_link', 'label' => '允许插入链接', 'type' => 'switcher', 'default' => false],
|
||||
['key' => 'comment_author_tag', 'label' => '显示“作者”标签', 'type' => 'switcher', 'default' => true, 'dependsOn' => ['key' => 'close_comments', 'value' => false]],
|
||||
['key' => 'user_edit_comment', 'label' => '允许用户编辑评论', 'type' => 'switcher', 'default' => true, 'dependsOn' => ['key' => 'close_comments', 'value' => false]],
|
||||
['key' => 'comment_like_s', 'label' => '评论点赞功能', 'type' => 'switcher', 'default' => true, 'dependsOn' => ['key' => 'close_comments', 'value' => false]],
|
||||
['key' => 'comment_user_url_s', 'label' => '匿名评论允许输入链接', 'type' => 'switcher', 'default' => false, 'dependsOn' => ['key' => 'close_comments', 'value' => false], 'description' => '用户未登录评论时,允许输入用户博客地址'],
|
||||
['key' => 'comment_corderby', 'label' => '评论排序功能', 'type' => 'switcher', 'default' => true, 'dependsOn' => ['all' => [['key' => 'close_comments', 'value' => false], ['key' => 'comment_like_s', 'value' => true]]], 'description' => '显示“最新、最热”排序按钮'],
|
||||
['key' => 'comment_title', 'label' => '自定义评论标题', 'type' => 'textarea', 'default' => '评论', 'rows' => 1, 'dependsOn' => ['key' => 'close_comments', 'value' => false]],
|
||||
['key' => 'comment_submit_text', 'label' => '自定义评论提交按钮文案', 'type' => 'textarea', 'default' => '提交评论', 'rows' => 1, 'dependsOn' => ['key' => 'close_comments', 'value' => false]],
|
||||
['key' => 'comment_text', 'label' => '自定义评论框占位符文案', 'type' => 'input', 'default' => '欢迎您留下宝贵的见解!', 'dependsOn' => ['key' => 'close_comments', 'value' => false]],
|
||||
]],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -163,7 +163,7 @@ class CommentActions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Permission: can edit? (author within configured window, or moderator)
|
||||
* Permission: can edit? (author with 允许用户编辑评论 on, or moderator)
|
||||
*/
|
||||
public function check_edit_permission(\WP_REST_Request $request): bool {
|
||||
if (!is_user_logged_in()) return false;
|
||||
|
||||
@@ -339,12 +339,13 @@ class PostDisplay {
|
||||
|
||||
public static function get_comment_display_settings(): array {
|
||||
$settings = Settings::get_all();
|
||||
$order = sanitize_key((string) ($settings['comment_order'] ?? 'desc'));
|
||||
|
||||
// 评论排序由 WP 讨论设置决定(与参考主题一致:主题不再提供排序配置)。
|
||||
$order = sanitize_key((string) get_option('comment_order', 'desc'));
|
||||
if (!in_array($order, ['asc', 'desc'], true)) {
|
||||
$order = 'desc';
|
||||
}
|
||||
|
||||
$empty_text = trim((string) ($settings['comment_empty_text'] ?? ''));
|
||||
$submit_text = trim((string) ($settings['comment_submit_text'] ?? ''));
|
||||
$box_placeholder = trim((string) ($settings['comment_text'] ?? ''));
|
||||
$title = trim((string) ($settings['comment_title'] ?? ''));
|
||||
@@ -354,11 +355,8 @@ class PostDisplay {
|
||||
'pagination_mode' => self::get_comment_pagination_mode(),
|
||||
'paging_ajax_ias' => !isset($settings['comment_paging_ajax_ias_s']) || !empty($settings['comment_paging_ajax_ias_s']),
|
||||
'paging_ajax_ias_max'=> max(0, min(10, (int) ($settings['comment_paging_ajax_ias_max'] ?? 3))),
|
||||
'per_page' => max(5, min(100, (int) ($settings['comment_per_page'] ?? 20))),
|
||||
'nested_depth' => max(1, min(10, (int) ($settings['comment_nested_depth'] ?? 3))),
|
||||
'require_login' => Settings::comment_requires_registration(),
|
||||
'avatar_size' => max(24, min(96, (int) ($settings['comment_avatar_size'] ?? 48))),
|
||||
'empty_text' => $empty_text !== '' ? $empty_text : __('暂无评论,来做第一个评论的人吧~', 'aksrt'),
|
||||
'box_hide' => sanitize_key((string) ($settings['comment_box_hide'] ?? '')),
|
||||
'toolbar' => [
|
||||
'code' => !isset($settings['comment_code']) || !empty($settings['comment_code']),
|
||||
'image' => !isset($settings['comment_img']) || !empty($settings['comment_img']),
|
||||
@@ -372,34 +370,15 @@ class PostDisplay {
|
||||
'like_enabled' => !isset($settings['comment_like_s']) || !empty($settings['comment_like_s']),
|
||||
'author_tag' => !isset($settings['comment_author_tag']) || !empty($settings['comment_author_tag']),
|
||||
'corderby' => !isset($settings['comment_corderby']) || !empty($settings['comment_corderby']),
|
||||
'edit_window' => max(0, min(1440, (int) ($settings['comment_edit_window'] ?? 10))),
|
||||
'user_edit' => !isset($settings['user_edit_comment']) || !empty($settings['user_edit_comment']),
|
||||
'submit_text' => $submit_text !== '' ? $submit_text : __('提交评论', 'aksrt'),
|
||||
'box_placeholder' => $box_placeholder !== '' ? $box_placeholder : __('说点什么吧...', 'aksrt'),
|
||||
'title' => $title !== '' ? $title : __('评论', 'aksrt'),
|
||||
// Extended legacy-parity settings.
|
||||
'close_comments' => !empty($settings['comment_close_comments']),
|
||||
'hot_threshold' => max(1, min(999, (int) ($settings['comment_hot_threshold'] ?? 10))),
|
||||
'close_comments' => !empty($settings['close_comments']),
|
||||
'user_url' => !empty($settings['comment_user_url_s']),
|
||||
'city_s' => !isset($settings['comment_city_s']) || !empty($settings['comment_city_s']),
|
||||
'city_type' => self::normalize_comment_city_type((string) ($settings['comment_city_type'] ?? 'province_city')),
|
||||
];
|
||||
}
|
||||
|
||||
private static function normalize_comment_city_type(string $type): string {
|
||||
$type = sanitize_key($type);
|
||||
// Map legacy legacy pro/city labels.
|
||||
if ($type === 'pro') {
|
||||
return 'province';
|
||||
}
|
||||
if ($type === 'city') {
|
||||
return 'province_city';
|
||||
}
|
||||
return in_array($type, ['province_city', 'province', 'country_province'], true)
|
||||
? $type
|
||||
: 'province_city';
|
||||
}
|
||||
|
||||
|
||||
public static function apply_list_orderby($query): void {
|
||||
if (is_admin() || !($query instanceof \WP_Query) || !$query->is_main_query()) {
|
||||
return;
|
||||
@@ -467,11 +446,9 @@ class PostDisplay {
|
||||
}
|
||||
|
||||
public static function get_comment_pagination_mode(): string {
|
||||
$mode = (string) Settings::get_value('comment_pagination_type', 'numbered');
|
||||
if ($mode === 'page') {
|
||||
$mode = 'numbered';
|
||||
}
|
||||
return in_array($mode, ['numbered', 'load_more', 'infinite'], true) ? $mode : 'numbered';
|
||||
// 与参考主题一致:ajax_lists = AJAX 追加列表翻页,其余为数字翻页按钮。
|
||||
$mode = (string) Settings::get_value('comment_paginate_type', 'default');
|
||||
return $mode === 'ajax_lists' ? 'ajax_lists' : 'numbered';
|
||||
}
|
||||
|
||||
private static function sanitize_custom_filter_defs($raw): array {
|
||||
|
||||
Reference in New Issue
Block a user