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:
@@ -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