fix(reports): separate readable categories from report content

Store readable category snapshots separately from details and evidence, validate report categories, and preserve context in admin displays and moderation actions. Widen report categories to TEXT and bump the schema to 3.2.0 without legacy data conversion.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Fable 5 committed 2026-10-31 00:57:13 +08:00
1 parent b2811cc248
commit b45fd161f0
16 files changed
+797 -75

No files matched your search

+15 -10
View File
@@ -26,33 +26,37 @@ class ReportCenter {
* @param int $reporter_id 举报人 ID
* @param string $target_type 举报目标类型 (post/comment/user)
* @param int $target_id 目标 ID
* @param string $reason 举报原因
* @param string $category 举报分类
* @param string $reason 补充说明与举证
* @param string $category 举报分类名称
* @return int 举报 ID(0 表示失败)
*/
public function submit(int $reporter_id, string $target_type, int $target_id, string $reason, string $category = ''): int {
public function submit(int $reporter_id, string $target_type, int $target_id, string $reason, string $category): int {
if ($reporter_id <= 0 || $target_id <= 0) return 0;
$valid_types = ['post', 'comment', 'user'];
if (!in_array($target_type, $valid_types, true)) return 0;
$category = sanitize_text_field($category);
$reason = sanitize_textarea_field($reason);
if ($category === '') return 0;
$table = $this->table();
if ($table === '') return 0;
global $wpdb;
$wpdb->insert($table, [
$inserted = $wpdb->insert($table, [
'reporter_id' => $reporter_id,
'target_type' => sanitize_key($target_type),
'target_id' => $target_id,
'reason' => sanitize_textarea_field($reason),
'category' => sanitize_key($category),
'reason' => $reason,
'category' => $category,
'status' => 'pending',
'created_at' => current_time('mysql'),
], ['%d', '%s', '%d', '%s', '%s', '%s', '%s']);
if ($inserted === false) return 0;
$id = $wpdb->insert_id ? (int) $wpdb->insert_id : 0;
if ($id > 0) {
$this->notify_admins_new_report($reporter_id, $target_type, $target_id, sanitize_textarea_field($reason));
$this->notify_admins_new_report($reporter_id, $target_type, $target_id, $category, $reason);
do_action('aksrt_report_submitted', $id, [
'reporter_id' => $reporter_id,
'target_type' => $target_type,
@@ -67,17 +71,18 @@ class ReportCenter {
/**
* 举报提交 → 管理员站内信(与禁封申诉同模式:直达工单列表)。
*/
private function notify_admins_new_report(int $reporter_id, string $target_type, int $target_id, string $reason): void {
private function notify_admins_new_report(int $reporter_id, string $target_type, int $target_id, string $category, string $reason): void {
if (!class_exists('\AKSRT\Messages\Message') || !class_exists('WP_User_Query')) return;
$type_labels = ['post' => __('文章', 'aksrt'), 'comment' => __('评论', 'aksrt'), 'user' => __('用户', 'aksrt')];
$reporter = get_userdata($reporter_id);
$summary = $category . ($reason !== '' ? ':' . $reason : '');
$content = sprintf(
/* translators: 1: reporter name 2: target type 3: target id 4: reason */
/* translators: 1: reporter name 2: target type 3: target id 4: report summary */
__('用户 %1$s 举报了%2$s #%3$d:%4$s', 'aksrt'),
$reporter instanceof \WP_User ? $reporter->display_name : __('匿名用户', 'aksrt'),
$type_labels[$target_type] ?? $target_type,
$target_id,
mb_substr($reason, 0, 80)
mb_substr($summary, 0, 80)
);
$admins = get_users(['role' => 'administrator', 'fields' => 'ID', 'number' => 20]);
foreach ($admins as $admin_id) {