fix(frontend): stop infinite pagination admin-ajax 400 spam

Hardened list-page infinite scroll so it no longer auto-fires three
admin-ajax requests on first paint, returns machine-readable nonce
errors, localizes aksrtData earlier for core modules, and ignores
UI-only data-action clicks.
This commit is contained in:
2026-07-13 09:45:05 +08:00
parent 964a6c9397
commit bf49982d16
4 changed files with 179 additions and 66 deletions
+18 -4
View File
@@ -281,7 +281,11 @@ class AKSRT_Admin {
public function ajax_load_more_posts(): void {
check_ajax_referer('aksrt_public_nonce', 'nonce');
$nonce = isset($_POST['nonce']) ? (string) wp_unslash($_POST['nonce']) : '';
if ($nonce === '' || !wp_verify_nonce($nonce, 'aksrt_public_nonce')) {
wp_send_json_error(['message' => __('安全验证失败', 'aksrt')], 403);
}
$page = max(1, (int) ($_POST['page'] ?? 1));
$query_vars = json_decode(wp_unslash((string) ($_POST['query_vars'] ?? '{}')), true);
$render_config = json_decode(wp_unslash((string) ($_POST['render_config'] ?? '{}')), true);
@@ -300,13 +304,19 @@ class AKSRT_Admin {
$render_config = array_merge($resolved, $render_config);
}
$query_vars['paged'] = $page;
if (empty($query_vars['post_status'])) {
$query_vars['post_status'] = 'publish';
}
if (empty($query_vars['post_type'])) {
$query_vars['post_type'] = 'post';
}
$query = new WP_Query($query_vars);
ob_start();
if (function_exists('aksrt_render_post_list')) {
aksrt_render_post_list($query, $render_config, true);
}
$html = ob_get_clean();
$html = (string) ob_get_clean();
wp_send_json_success([
'html' => $html,
@@ -316,11 +326,15 @@ class AKSRT_Admin {
}
public function ajax_load_more_comments(): void {
check_ajax_referer('aksrt_public_nonce', 'nonce');
$nonce = isset($_POST['nonce']) ? (string) wp_unslash($_POST['nonce']) : '';
if ($nonce === '' || !wp_verify_nonce($nonce, 'aksrt_public_nonce')) {
wp_send_json_error(['message' => __('安全验证失败', 'aksrt')], 403);
}
$post_id = absint($_POST['post_id'] ?? 0);
$page = max(1, (int) ($_POST['page'] ?? 1));
if ($post_id <= 0) {
wp_send_json_error(['message' => __('无效的文章 ID', 'aksrt')]);
wp_send_json_error(['message' => __('无效的文章 ID', 'aksrt')], 400);
}
$order = sanitize_key((string) ($_POST['comment_order'] ?? $_POST['order'] ?? 'newest'));