fix(report): carry the admin note into the reporter result email
update_status() fired aksrt_report_status_changed without the note and
the mail listener hard-coded note => '', so the reply-to-reporter
comment written in the process form never reached the email. Pass the
sanitized note as a 4th action arg, render it via the existing {note}
placeholder, and map the raw status key to its Chinese label in the
email body. Contract test extended accordingly.
This commit is contained in:
1 parent
044830b58a
commit
c7a552dfd5
3 files changed
+28
-6
No files matched your search
@@ -140,10 +140,11 @@ class ReportCenter {
|
|||||||
];
|
];
|
||||||
$format = ['%s', '%s'];
|
$format = ['%s', '%s'];
|
||||||
|
|
||||||
if ($note !== '') {
|
$note_clean = $note !== '' ? sanitize_textarea_field($note) : '';
|
||||||
|
if ($note_clean !== '') {
|
||||||
$notes = json_decode($existing->notes_json ?? '[]', true) ?? [];
|
$notes = json_decode($existing->notes_json ?? '[]', true) ?? [];
|
||||||
$notes[] = [
|
$notes[] = [
|
||||||
'note' => sanitize_textarea_field($note),
|
'note' => $note_clean,
|
||||||
'status' => $new_status,
|
'status' => $new_status,
|
||||||
'operator' => get_current_user_id(),
|
'operator' => get_current_user_id(),
|
||||||
'timestamp' => current_time('mysql'),
|
'timestamp' => current_time('mysql'),
|
||||||
@@ -154,7 +155,8 @@ class ReportCenter {
|
|||||||
|
|
||||||
$result = $wpdb->update($table, $update_data, ['id' => $report_id], $format, ['%d']);
|
$result = $wpdb->update($table, $update_data, ['id' => $report_id], $format, ['%d']);
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
do_action('aksrt_report_status_changed', $report_id, (int) ($existing->reporter_id ?? 0), $new_status);
|
// 第 4 参携带处理说明:邮件通知(report_result)需要反馈给举报人。
|
||||||
|
do_action('aksrt_report_status_changed', $report_id, (int) ($existing->reporter_id ?? 0), $new_status, $note_clean);
|
||||||
}
|
}
|
||||||
return $result !== false;
|
return $result !== false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ final class MailNotifications {
|
|||||||
add_action('aksrt_new_posts_pending', [self::class, 'post_pending'], 20, 1);
|
add_action('aksrt_new_posts_pending', [self::class, 'post_pending'], 20, 1);
|
||||||
add_action('transition_post_status', [self::class, 'post_status_changed'], 20, 3);
|
add_action('transition_post_status', [self::class, 'post_status_changed'], 20, 3);
|
||||||
add_action('aksrt_report_submitted', [self::class, 'report_submitted'], 20, 2);
|
add_action('aksrt_report_submitted', [self::class, 'report_submitted'], 20, 2);
|
||||||
add_action('aksrt_report_status_changed', [self::class, 'report_status_changed'], 20, 3);
|
add_action('aksrt_report_status_changed', [self::class, 'report_status_changed'], 20, 4);
|
||||||
add_action('aksrt_friend_link_submitted', [self::class, 'friend_link_submitted'], 20, 1);
|
add_action('aksrt_friend_link_submitted', [self::class, 'friend_link_submitted'], 20, 1);
|
||||||
add_action('aksrt_user_phone_changed', [self::class, 'phone_changed'], 20, 2);
|
add_action('aksrt_user_phone_changed', [self::class, 'phone_changed'], 20, 2);
|
||||||
add_action('aksrt_user_restriction_changed', [self::class, 'restriction_changed'], 20, 4);
|
add_action('aksrt_user_restriction_changed', [self::class, 'restriction_changed'], 20, 4);
|
||||||
@@ -179,9 +179,24 @@ final class MailNotifications {
|
|||||||
self::send_admin('report_admin', ['username' => $reporter instanceof \WP_User ? $reporter->display_name : __('用户', 'aksrt'), 'title' => (string) ($report['target_type'] ?? ''), 'url' => admin_url('users.php?page=aksrt_user_ban')]);
|
self::send_admin('report_admin', ['username' => $reporter instanceof \WP_User ? $reporter->display_name : __('用户', 'aksrt'), 'title' => (string) ($report['target_type'] ?? ''), 'url' => admin_url('users.php?page=aksrt_user_ban')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function report_status_changed(int $report_id, int $reporter_id, string $status): void {
|
public static function report_status_changed(int $report_id, int $reporter_id, string $status, string $note = ''): void {
|
||||||
$reporter = get_userdata($reporter_id);
|
$reporter = get_userdata($reporter_id);
|
||||||
if ($reporter instanceof \WP_User) self::send('report_result', $reporter->user_email, ['username' => $reporter->display_name, 'status' => $status, 'note' => '', 'url' => home_url('/')]);
|
if (!$reporter instanceof \WP_User) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 状态值中文化后进入邮件;处理说明来自后台“处理说明”输入(钩子第 4 参)。
|
||||||
|
$labels = [
|
||||||
|
'pending' => __('待处理', 'aksrt'),
|
||||||
|
'reviewing' => __('审核中', 'aksrt'),
|
||||||
|
'resolved' => __('已解决', 'aksrt'),
|
||||||
|
'dismissed' => __('已驳回', 'aksrt'),
|
||||||
|
];
|
||||||
|
self::send('report_result', $reporter->user_email, [
|
||||||
|
'username' => $reporter->display_name,
|
||||||
|
'status' => $labels[$status] ?? $status,
|
||||||
|
'note' => $note !== '' ? $note : __('—', 'aksrt'),
|
||||||
|
'url' => home_url('/'),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function friend_link_submitted(array $link): void {
|
public static function friend_link_submitted(array $link): void {
|
||||||
|
|||||||
@@ -137,6 +137,11 @@ test('admin report notification links to the real page', () => {
|
|||||||
assert.match(mailNotifications, /users\.php\?page=aksrt_user_ban'/)
|
assert.match(mailNotifications, /users\.php\?page=aksrt_user_ban'/)
|
||||||
assert.ok(!mailNotifications.includes('page=aksrt_reports&'), 'dead admin page link')
|
assert.ok(!mailNotifications.includes('page=aksrt_reports&'), 'dead admin page link')
|
||||||
assert.ok(!mailNotifications.includes('tab=reports'), 'merged ticket page has no reports tab')
|
assert.ok(!mailNotifications.includes('tab=reports'), 'merged ticket page has no reports tab')
|
||||||
|
// 处理说明必须随 aksrt_report_status_changed 传入邮件载荷(此前硬编码空串,
|
||||||
|
// 举报人收到的“说明:”永远为空)。
|
||||||
|
assert.match(reportCenter, /do_action\('aksrt_report_status_changed', \$report_id[\s\S]*?new_status, \$note_clean\)/)
|
||||||
|
assert.match(mailNotifications, /function report_status_changed\(int \$report_id, int \$reporter_id, string \$status, string \$note = ''\)/)
|
||||||
|
assert.match(mailNotifications, /'note'\s*=>\s*\$note !== '' \? \$note :/)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('native ban page mirrors the reference theme layout', () => {
|
test('native ban page mirrors the reference theme layout', () => {
|
||||||
|
|||||||
Reference in new issue
Block a user