fix(report): unify the frontend report entry and modal

- enqueue report.js on singular pages too: the single meta box and
  comment report buttons rendered without their script handler, so
  clicking the report item did nothing
- align the report runtime default with the admin schema and the
  reference theme (user_report_s default true) so the public user
  home cover menu shows the report entry
- rebuild report.js on top of AksrtModalRuntime following the
  reference theme modal format: red warning header, preset reason
  badges with an other-reason textarea, violation link field, detail
  description and a cancel/submit footer; submit goes through the
  unified /report/submit endpoint
- keep report inside the comment three-dot dropdown and enrich the
  payload (target name/avatar) for the modal; inject configured
  report categories via aksrtData.reportCategories
- update the report contract test accordingly
This commit is contained in:
2026-09-20 13:40:05 +08:00
parent 381256ed59
commit 7c730b83d6
9 changed files with 249 additions and 112 deletions
+6 -1
View File
@@ -137,7 +137,12 @@ if (!function_exists('aksrt_get_single_meta_box')) :
}
$more .= '<button type="button" class="post-drop-meta__item" data-share-copy data-share-url="' . esc_url((string) $permalink) . '"><i class="fa fas fa-link" aria-hidden="true"></i><span>' . esc_html__('复制链接', 'aksrt') . '</span></button>';
if (is_user_logged_in()) {
$more .= '<button type="button" class="post-drop-meta__item" data-aksrt-report=\'{"target_type":"post","target_id":' . (int) $post_id . '}\'><i class="fa fas fa-flag" aria-hidden="true"></i><span>' . esc_html__('举报', 'aksrt') . '</span></button>';
$report_payload = wp_json_encode([
'target_type' => 'post',
'target_id' => (int) $post_id,
'target_name' => get_the_title($post_id),
]);
$more .= '<button type="button" class="post-drop-meta__item" data-aksrt-report="' . esc_attr((string) $report_payload) . '"><i class="fa fas fa-flag" aria-hidden="true"></i><span>' . esc_html__('举报', 'aksrt') . '</span></button>';
} else {
$more .= '<a href="' . esc_url($login_url) . '" class="post-drop-meta__item"><i class="fa fas fa-flag" aria-hidden="true"></i><span>' . esc_html__('登录后举报', 'aksrt') . '</span></a>';
}
+10 -1
View File
@@ -147,6 +147,8 @@ if (!function_exists('aksrt_get_comment_report_html')) :
/**
* 评论举报入口 — 登录用户可举报他人评论(前台走 report.js 的 data-aksrt-report 契约)。
*
* 举报位于“回复”右侧三点下拉菜单内(参考主题同位置)。
*
* @param WP_Comment $comment Comment.
* @return string
*/
@@ -169,7 +171,14 @@ if (!function_exists('aksrt_get_comment_report_html')) :
return '';
}
return '<li><a class="comment-report-link" href="javascript:;" data-aksrt-report=\'{"target_type":"comment","target_id":' . (int) $comment->comment_ID . '}\'><i class="fa fas fa-flag mr10 fa-fw" aria-hidden="true"></i><text>' . esc_html__('举报', 'aksrt') . '</text></a></li>';
$report_payload = wp_json_encode([
'target_type' => 'comment',
'target_id' => (int) $comment->comment_ID,
'target_name' => get_comment_author($comment),
'target_avatar' => get_avatar_url((int) $comment->user_id > 0 ? (int) $comment->user_id : 0, ['size' => 40]) ?: '',
]);
return '<li><a class="comment-report-link" href="javascript:;" data-aksrt-report="' . esc_attr((string) $report_payload) . '"><i class="fa fa-exclamation-triangle mr10 fa-fw c-red" aria-hidden="true"></i>' . esc_html__('举报', 'aksrt') . '</a></li>';
}
endif;