feat(admin): rebuild ban page to mirror the reference theme
- rename the users.php submenu to 举报&禁封申诉 and the page heading to 用户禁封申诉及用户举报管理 - merge report tickets and ban appeals into one Zibll-style queue: type filter buttons (全部/禁封申诉/用户举报), status subsubsub (全部/待处理/已批准/已拒绝), search box, sortable widefat table with the same column set (状态/类型/提交用户/详情/提交时间/更新时间), inline process forms and 20-per-page pagination - report process form shows the reported target, restriction status and an enforcement action select; appeal form offers approve/reject radios with a message to the user - move restriction enforcement into ReportCenter::apply_action so REST and the native page share one implementation; add get_report_row() - drop the old three-tab rendering (reports/appeals tabs) and fix all notice/mail/SPA links to the merged page
This commit is contained in:
1 parent
3764d48755
commit
902e71ee62
8 files changed
+626
-217
No files matched your search
+40
-155
@@ -12,6 +12,7 @@ class UsersMenus {
|
||||
use UsersMenusVerify;
|
||||
use UsersMenusVip;
|
||||
use UsersMenusReferral;
|
||||
use UsersMenusTickets;
|
||||
|
||||
public const CAPABILITY = 'manage_options';
|
||||
|
||||
@@ -81,8 +82,8 @@ class UsersMenus {
|
||||
);
|
||||
add_submenu_page(
|
||||
'users.php',
|
||||
__('举报&禁封', 'aksrt'),
|
||||
__('举报&禁封', 'aksrt'),
|
||||
__('举报&禁封申诉', 'aksrt'),
|
||||
__('举报&禁封申诉', 'aksrt'),
|
||||
self::CAPABILITY,
|
||||
'aksrt_user_ban',
|
||||
[$this, 'render_ban_page']
|
||||
@@ -112,7 +113,7 @@ class UsersMenus {
|
||||
if ($page !== 'aksrt_user_ban' && class_exists('\AKSRT\Messages\ReportCenter')) {
|
||||
$pending_reports = (int) \AKSRT\Messages\ReportCenter::get_instance()->get_pending_count();
|
||||
if ($pending_reports > 0) {
|
||||
$url = admin_url('users.php?page=aksrt_user_ban&tab=reports&status=pending');
|
||||
$url = admin_url('users.php?page=aksrt_user_ban&status=pending');
|
||||
echo '<div class="notice notice-info is-dismissible"><h3>' . esc_html__('举报待处理', 'aksrt') . '</h3>';
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: %d count */
|
||||
@@ -131,7 +132,7 @@ class UsersMenus {
|
||||
'fields' => 'ID',
|
||||
]));
|
||||
if ($pending_appeals > 0) {
|
||||
$url = admin_url('users.php?page=aksrt_user_ban&tab=appeals&status=pending');
|
||||
$url = admin_url('users.php?page=aksrt_user_ban&type=appeal&status=pending');
|
||||
echo '<div class="notice notice-warning is-dismissible"><h3>' . esc_html__('禁封申诉待处理', 'aksrt') . '</h3>';
|
||||
echo '<p>' . esc_html(sprintf(__('您有 %d 条禁封申诉待处理', 'aksrt'), $pending_appeals)) . '</p>';
|
||||
echo '<p><a class="button button-primary" href="' . esc_url($url) . '">' . esc_html__('立即处理', 'aksrt') . '</a></p></div>';
|
||||
@@ -283,87 +284,27 @@ class UsersMenus {
|
||||
|
||||
public function render_ban_page(): void {
|
||||
$this->ensure_cap();
|
||||
echo '<div class="wrap"><h1>' . esc_html__('举报&禁封', 'aksrt') . '</h1>';
|
||||
echo '<div class="wrap"><h2>' . esc_html__('用户禁封申诉及用户举报管理', 'aksrt') . '</h2>';
|
||||
$this->flash();
|
||||
|
||||
$tab = isset($_GET['tab']) ? sanitize_key((string) wp_unslash($_GET['tab'])) : 'reports';
|
||||
$tab = isset($_GET['tab']) ? sanitize_key((string) wp_unslash($_GET['tab'])) : 'tickets';
|
||||
if (!in_array($tab, ['tickets', 'restrictions'], true)) {
|
||||
$tab = 'tickets';
|
||||
}
|
||||
|
||||
echo '<h2 class="nav-tab-wrapper">';
|
||||
printf('<a class="nav-tab%s" href="%s">%s</a>', $tab === 'reports' ? ' nav-tab-active' : '', esc_url(admin_url('users.php?page=aksrt_user_ban&tab=reports')), esc_html__('举报', 'aksrt'));
|
||||
printf('<a class="nav-tab%s" href="%s">%s</a>', $tab === 'tickets' ? ' nav-tab-active' : '', esc_url(admin_url('users.php?page=aksrt_user_ban')), esc_html__('申诉&举报', 'aksrt'));
|
||||
printf('<a class="nav-tab%s" href="%s">%s</a>', $tab === 'restrictions' ? ' nav-tab-active' : '', esc_url(admin_url('users.php?page=aksrt_user_ban&tab=restrictions')), esc_html__('禁封限制', 'aksrt'));
|
||||
printf('<a class="nav-tab%s" href="%s">%s</a>', $tab === 'appeals' ? ' nav-tab-active' : '', esc_url(admin_url('users.php?page=aksrt_user_ban&tab=appeals')), esc_html__('禁封申诉', 'aksrt'));
|
||||
echo '</h2>';
|
||||
|
||||
if ($tab === 'restrictions') {
|
||||
$this->render_restrictions_tab();
|
||||
} elseif ($tab === 'appeals') {
|
||||
$this->render_appeals_tab();
|
||||
} else {
|
||||
$this->render_reports_tab();
|
||||
$this->render_tickets_tab();
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
private function render_reports_tab(): void {
|
||||
if (!class_exists('\AKSRT\Messages\ReportCenter')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('举报中心未初始化。', 'aksrt') . '</p></div>';
|
||||
return;
|
||||
}
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : 'pending';
|
||||
$svc = \AKSRT\Messages\ReportCenter::get_instance();
|
||||
$counts = $svc->get_status_counts();
|
||||
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: 1 pending 2 total */
|
||||
__('待处理 %1$d / 共 %2$d', 'aksrt'),
|
||||
(int) ($counts['pending'] ?? 0),
|
||||
(int) ($counts['total'] ?? 0)
|
||||
)) . '</p>';
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_user_ban" /><input type="hidden" name="tab" value="reports" />';
|
||||
echo '<select name="status">';
|
||||
foreach (['pending' => __('待处理', 'aksrt'), 'reviewing' => __('审核中', 'aksrt'), 'resolved' => __('已处理', 'aksrt'), 'dismissed' => __('已驳回', 'aksrt'), '' => __('全部', 'aksrt')] as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$items = $svc->get_reports(['status' => $status, 'limit' => 50, 'offset' => 0]);
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('举报人', 'aksrt') . '</th><th>' . esc_html__('目标', 'aksrt') . '</th><th>' . esc_html__('原因', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('时间', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无举报', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$st = (string) ($row['status'] ?? '');
|
||||
$rid = (int) ($row['reporter_id'] ?? 0);
|
||||
$ru = $rid > 0 ? get_userdata($rid) : null;
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td>' . ($ru ? esc_html($ru->display_name) : esc_html((string) $rid)) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['target_type'] ?? '') . ' #' . (string) ($row['target_id'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['reason'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html($st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td><form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;gap:4px;align-items:center;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_users_update_report" />';
|
||||
echo '<input type="hidden" name="report_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_users_update_report_' . $id);
|
||||
echo '<select name="new_status">';
|
||||
foreach (['pending', 'reviewing', 'resolved', 'dismissed'] as $key) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($st, $key, false), esc_html($key));
|
||||
}
|
||||
echo '</select>';
|
||||
echo '<input type="text" name="note" placeholder="' . esc_attr__('备注', 'aksrt') . '" />';
|
||||
submit_button(__('更新', 'aksrt'), 'small', '', false);
|
||||
echo '</form></td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
}
|
||||
|
||||
private function render_restrictions_tab(): void {
|
||||
if (!class_exists('\AKSRT\User\Restriction')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('限制模块未初始化。', 'aksrt') . '</p></div>';
|
||||
@@ -436,12 +377,29 @@ class UsersMenus {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['report_id']) ? (int) $_POST['report_id'] : 0;
|
||||
$new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : '';
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
$id = isset($_POST['report_id']) ? (int) $_POST['report_id'] : 0;
|
||||
$new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : '';
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
$action_taken = isset($_POST['action_taken']) ? sanitize_key((string) wp_unslash($_POST['action_taken'])) : 'none';
|
||||
check_admin_referer('aksrt_users_update_report_' . $id);
|
||||
$ok = $id > 0 && class_exists('\AKSRT\Messages\ReportCenter') && \AKSRT\Messages\ReportCenter::get_instance()->update_status($id, $new_status, $note);
|
||||
$this->redirect('aksrt_user_ban', $ok ? 'report_updated' : 'report_failed', ['tab' => 'reports']);
|
||||
|
||||
$ok = false;
|
||||
if ($id > 0 && class_exists('\AKSRT\Messages\ReportCenter')) {
|
||||
$svc = \AKSRT\Messages\ReportCenter::get_instance();
|
||||
$ok = $svc->update_status($id, $new_status, $note);
|
||||
if ($ok && $action_taken !== '' && $action_taken !== 'none') {
|
||||
$row = $svc->get_report_row($id);
|
||||
if ($row) {
|
||||
$svc->apply_action(
|
||||
sanitize_key((string) $row['target_type']),
|
||||
(int) $row['target_id'],
|
||||
$action_taken,
|
||||
(string) ($row['reason'] ?? '')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->redirect('aksrt_user_ban', $ok ? 'report_updated' : 'report_failed', ['tab' => 'tickets']);
|
||||
}
|
||||
|
||||
public function handle_add_restriction(): void {
|
||||
@@ -471,90 +429,17 @@ class UsersMenus {
|
||||
$this->redirect('aksrt_user_ban', $ok ? 'restriction_removed' : 'restriction_failed', ['tab' => 'restrictions']);
|
||||
}
|
||||
|
||||
|
||||
private function render_appeals_tab(): void {
|
||||
if (!class_exists('\AKSRT\User\BanAppeal')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('申诉模块未初始化。', 'aksrt') . '</p></div>';
|
||||
return;
|
||||
}
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : 'pending';
|
||||
if (!in_array($status, ['pending', 'approved', 'rejected', 'all'], true)) {
|
||||
$status = 'pending';
|
||||
}
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_user_ban" /><input type="hidden" name="tab" value="appeals" />';
|
||||
echo '<select name="status">';
|
||||
foreach (['pending' => __('待处理', 'aksrt'), 'approved' => __('已通过', 'aksrt'), 'rejected' => __('已驳回', 'aksrt'), 'all' => __('全部', 'aksrt')] as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$users = get_users([
|
||||
'meta_key' => \AKSRT\User\BanAppeal::META_STATUS,
|
||||
'meta_compare' => 'EXISTS',
|
||||
'number' => 100,
|
||||
'fields' => ['ID', 'display_name', 'user_login', 'user_email'],
|
||||
'orderby' => 'ID',
|
||||
'order' => 'DESC',
|
||||
]);
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>UID</th><th>' . esc_html__('用户', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('类型', 'aksrt') . '</th><th>' . esc_html__('说明', 'aksrt') . '</th><th>' . esc_html__('提交时间', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
$shown = 0;
|
||||
foreach ($users as $u) {
|
||||
$uid = (int) $u->ID;
|
||||
$st = \AKSRT\User\BanAppeal::get_status($uid);
|
||||
if ($st === '') {
|
||||
continue;
|
||||
}
|
||||
if ($status !== 'all' && $st !== $status) {
|
||||
continue;
|
||||
}
|
||||
$payload = \AKSRT\User\BanAppeal::get_payload($uid);
|
||||
$shown++;
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $uid) . '</td>';
|
||||
echo '<td>' . esc_html($u->display_name . ' (' . $u->user_login . ')') . '<br><span class="description">' . esc_html($u->user_email) . '</span></td>';
|
||||
echo '<td>' . esc_html($st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($payload['reason_key'] ?? '—')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($payload['reason'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($payload['time'] ?? '—')) . '</td>';
|
||||
echo '<td>';
|
||||
if ($st === 'pending') {
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;gap:6px;flex-wrap:wrap;align-items:center;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_users_process_appeal" />';
|
||||
echo '<input type="hidden" name="user_id" value="' . esc_attr((string) $uid) . '" />';
|
||||
wp_nonce_field('aksrt_users_process_appeal_' . $uid);
|
||||
echo '<input type="text" name="note" placeholder="' . esc_attr__('处理备注', 'aksrt') . '" class="regular-text" />';
|
||||
echo '<button type="submit" name="decision" value="approve" class="button button-primary">' . esc_html__('通过并解封', 'aksrt') . '</button>';
|
||||
echo '<button type="submit" name="decision" value="reject" class="button">' . esc_html__('驳回', 'aksrt') . '</button>';
|
||||
echo '</form>';
|
||||
} else {
|
||||
echo '—';
|
||||
}
|
||||
echo '</td></tr>';
|
||||
}
|
||||
if ($shown < 1) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无申诉', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
}
|
||||
|
||||
public function handle_process_appeal(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
|
||||
$user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
|
||||
$decision = isset($_POST['decision']) ? sanitize_key((string) wp_unslash($_POST['decision'])) : '';
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
check_admin_referer('aksrt_users_process_appeal_' . $user_id);
|
||||
|
||||
if ($user_id <= 0 || !in_array($decision, ['approve', 'reject'], true) || !class_exists('\AKSRT\User\BanAppeal')) {
|
||||
$this->redirect('aksrt_user_ban', 'appeal_failed', ['tab' => 'appeals']);
|
||||
$this->redirect('aksrt_user_ban', 'appeal_failed', ['tab' => 'tickets', 'type' => 'appeal']);
|
||||
}
|
||||
|
||||
$status = $decision === 'approve' ? 'approved' : 'rejected';
|
||||
@@ -564,7 +449,7 @@ class UsersMenus {
|
||||
$payload['admin_note'] = $note;
|
||||
$payload['handled_at'] = current_time('Y-m-d H:i');
|
||||
$payload['handled_by'] = get_current_user_id();
|
||||
$payload['decision'] = $status;
|
||||
$payload['decision'] = $status;
|
||||
update_user_meta($user_id, \AKSRT\User\BanAppeal::META_PAYLOAD, $payload);
|
||||
|
||||
$history = get_user_meta($user_id, \AKSRT\User\BanAppeal::META_HISTORY, true);
|
||||
@@ -598,7 +483,7 @@ class UsersMenus {
|
||||
$this->redirect(
|
||||
'aksrt_user_ban',
|
||||
$decision === 'approve' ? 'appeal_approved' : 'appeal_rejected',
|
||||
['tab' => 'appeals']
|
||||
['tab' => 'tickets', 'type' => 'appeal']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user