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:
@@ -63,6 +63,32 @@ add_filter('comments_template_query_args', static function ($args) {
|
||||
: $args;
|
||||
});
|
||||
|
||||
if (!function_exists('aksrt_comment_box_visible')) :
|
||||
/**
|
||||
* Whether the comment module may render for the current visitor.
|
||||
*
|
||||
* Mirrors the reference theme's comment_box_hide conditions.
|
||||
*/
|
||||
function aksrt_comment_box_visible(): bool {
|
||||
$settings = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_comment_display_settings()
|
||||
: [];
|
||||
$hide = sanitize_key((string) ($settings['box_hide'] ?? ''));
|
||||
switch ($hide) {
|
||||
case 'signin':
|
||||
return is_user_logged_in();
|
||||
case 'vip':
|
||||
return function_exists('aksrt_is_vip') && aksrt_is_vip();
|
||||
case 'vip_2':
|
||||
return function_exists('aksrt_is_vip2') && aksrt_is_vip2();
|
||||
case 'auth':
|
||||
return function_exists('aksrt_current_user_is_verified') && aksrt_current_user_is_verified();
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_comments_build_context')) :
|
||||
/**
|
||||
* Resolve comments runtime context once.
|
||||
@@ -116,6 +142,7 @@ if (!function_exists('aksrt_comments_build_context')) :
|
||||
'title_text' => (string) ($settings['title'] ?? __('评论', 'aksrt')),
|
||||
'corderby_enabled' => !empty($settings['corderby']),
|
||||
'close_comments' => !empty($settings['close_comments']),
|
||||
'box_hidden' => !aksrt_comment_box_visible(),
|
||||
'oauth_providers' => class_exists('\AKSRT\Auth\OAuth')
|
||||
? \AKSRT\Auth\OAuth::get_instance()->get_auth_providers_data()
|
||||
: [],
|
||||
@@ -646,7 +673,7 @@ if (!function_exists('aksrt_comments_render')) :
|
||||
}
|
||||
|
||||
$ctx = aksrt_comments_build_context();
|
||||
if (!empty($ctx['close_comments'])) {
|
||||
if (!empty($ctx['close_comments']) || !empty($ctx['box_hidden'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,26 @@ if (!function_exists('aksrt_get_user_identity_signals')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_current_user_is_verified')) {
|
||||
/**
|
||||
* Whether the current user carries a verification (认证) signal.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function aksrt_current_user_is_verified(): bool {
|
||||
$user_id = get_current_user_id();
|
||||
if ($user_id <= 0 || !function_exists('aksrt_get_user_identity_signals')) {
|
||||
return false;
|
||||
}
|
||||
foreach (aksrt_get_user_identity_signals($user_id) as $signal) {
|
||||
if ((string) ($signal['type'] ?? '') === 'verify') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_render_user_identity_chips')) {
|
||||
/**
|
||||
* Render compact identity chips (verify / level / badges).
|
||||
@@ -537,7 +557,8 @@ if (!function_exists('aksrt_get_worn_medal_icon')) {
|
||||
|
||||
if (!function_exists('aksrt_is_blog_comment_hot')) {
|
||||
/**
|
||||
* "神评" for ordinary post comments when likes cross threshold.
|
||||
* "神评" for ordinary post comments when likes cross the fixed threshold
|
||||
* (参考主题固定 10 赞,主题不再提供该阈值配置).
|
||||
*/
|
||||
function aksrt_is_blog_comment_hot($comment): bool {
|
||||
$comment_id = $comment instanceof WP_Comment ? (int) $comment->comment_ID : (int) $comment;
|
||||
@@ -548,16 +569,6 @@ if (!function_exists('aksrt_is_blog_comment_hot')) {
|
||||
return true;
|
||||
}
|
||||
$threshold = 10;
|
||||
if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_comment_display_settings')) {
|
||||
$display = \AKSRT\Settings\Settings::get_comment_display_settings();
|
||||
if (isset($display['hot_threshold'])) {
|
||||
$threshold = max(1, (int) $display['hot_threshold']);
|
||||
}
|
||||
}
|
||||
$all = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_all() : [];
|
||||
if (isset($all['comment_hot_threshold'])) {
|
||||
$threshold = max(1, (int) $all['comment_hot_threshold']);
|
||||
}
|
||||
$likes = function_exists('aksrt_get_comment_likes') ? aksrt_get_comment_likes($comment_id) : (int) get_comment_meta($comment_id, 'aksrt_comment_likes', true);
|
||||
if ($likes < $threshold) {
|
||||
return false;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Gates:
|
||||
* master: ip_geo_enabled
|
||||
* surface: ip_geo_display ∈ {comment, user_home, user_center, post}
|
||||
* comments: comment_city_s (+ comment_city_type) via comments/geo.php
|
||||
* comments: display + format fully owned by this extension via comments/geo.php
|
||||
*
|
||||
* Meta:
|
||||
* comment → aksrt_comment_addr {country,province,city}
|
||||
|
||||
@@ -40,15 +40,14 @@ if (!function_exists('aksrt_comment_action_permissions')) :
|
||||
return false;
|
||||
};
|
||||
|
||||
$edit_window = 10;
|
||||
// 允许用户编辑评论:参考主题 user_edit_comment 总开关(关闭后本人亦不可编辑)。
|
||||
$user_edit = true;
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
$display = \AKSRT\Settings\Settings::get_comment_display_settings();
|
||||
$edit_window = (int) ($display['edit_window'] ?? 10);
|
||||
$user_edit = !isset($display['user_edit']) || !empty($display['user_edit']);
|
||||
}
|
||||
$within_window = $edit_window > 0
|
||||
&& (time() - strtotime((string) $comment->comment_date_gmt)) < ($edit_window * MINUTE_IN_SECONDS);
|
||||
|
||||
$can_edit_own = $is_owner && $within_window && $can('comment_edit');
|
||||
$can_edit_own = $is_owner && $user_edit && $can('comment_edit');
|
||||
$can_edit_others = (!$is_owner) && (
|
||||
($is_post_author && $can('comment_edit_my_post'))
|
||||
|| $can('comment_edit_other')
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Comment city / IP geo helpers.
|
||||
*
|
||||
* Meta: aksrt_comment_addr {country,province,city}
|
||||
* Gates: ip_geo_enabled + ip_geo_display has comment + comment_city_s
|
||||
* Gates: ip_geo_enabled + ip_geo_display has comment(扩展&增强 / IP归属地统一控制)
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -12,27 +12,14 @@ defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_comment_city_enabled')) :
|
||||
function aksrt_comment_city_enabled(): bool {
|
||||
if (function_exists('aksrt_ip_geo_display_enabled') && !aksrt_ip_geo_display_enabled('comment')) {
|
||||
return false;
|
||||
}
|
||||
if (!class_exists('\AKSRT\Settings\Settings')) {
|
||||
return false;
|
||||
}
|
||||
$s = \AKSRT\Settings\Settings::get_comment_display_settings();
|
||||
return !empty($s['city_s']);
|
||||
// 评论区位置显示的开关与精度统一由「扩展&增强 / IP归属地」配置提供。
|
||||
return function_exists('aksrt_ip_geo_display_enabled') && aksrt_ip_geo_display_enabled('comment');
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_comment_city_type')) :
|
||||
function aksrt_comment_city_type(): string {
|
||||
if (!class_exists('\AKSRT\Settings\Settings')) {
|
||||
return function_exists('aksrt_ip_geo_format_key') ? aksrt_ip_geo_format_key() : 'province_city';
|
||||
}
|
||||
$s = \AKSRT\Settings\Settings::get_comment_display_settings();
|
||||
$type = sanitize_key((string) ($s['city_type'] ?? 'province_city'));
|
||||
return in_array($type, ['province_city', 'province', 'country_province'], true)
|
||||
? $type
|
||||
: 'province_city';
|
||||
return function_exists('aksrt_ip_geo_format_key') ? aksrt_ip_geo_format_key() : 'province_city';
|
||||
}
|
||||
endif;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user