refactor(submit): remove unused aksrt_update_post ajax endpoint

No caller anywhere: front JS updates via aksrt_submit_post (posts_id),
guests via aksrt_save_draft. Re-pin the one-captcha-admission contract
to ajax_submit_post, the only non-draft entry point.
This commit is contained in:
2026-09-05 23:41:12 +08:00
parent 5fbcfa2b49
commit d84d485ec7
2 changed files with 5 additions and 24 deletions
-20
View File
@@ -30,7 +30,6 @@ class FrontSubmit {
public function init(): void {
add_action('wp_ajax_aksrt_submit_post', [$this, 'ajax_submit_post']);
add_action('wp_ajax_aksrt_save_draft', [$this, 'ajax_save_draft']);
add_action('wp_ajax_aksrt_update_post', [$this, 'ajax_update_post']);
add_action('wp_ajax_aksrt_delete_draft', [$this, 'ajax_delete_draft']);
add_action('wp_ajax_aksrt_delete_post', [$this, 'ajax_delete_post']);
@@ -383,25 +382,6 @@ class FrontSubmit {
$this->send_result($result);
}
public function ajax_update_post(): void {
$this->verify_nonce();
$data = wp_unslash($_POST);
if (!is_array($data)) {
$data = [];
}
$post_id = absint($data['posts_id'] ?? $data['post_id'] ?? $data['edit_id'] ?? 0);
if ($post_id <= 0) {
wp_send_json_error(['message' => __('文章 ID 无效', 'aksrt')]);
}
$data['posts_id'] = $post_id;
$action = (($data['status'] ?? '') === 'draft') ? 'posts_draft' : 'posts_save';
if ($action !== 'posts_draft') {
$this->verify_captcha();
}
$result = $this->persist($data, $action);
$this->send_result($result);
}
public function ajax_delete_draft(): void {
$this->verify_nonce();
$user_id = get_current_user_id();
@@ -100,12 +100,13 @@ test('public theme does not inject a global focus-visible ring', () => {
test('non-draft front-submit updates require one server captcha admission', () => {
const controller = read('src/Core/FrontSubmit.php');
const start = controller.indexOf('public function ajax_update_post(): void');
const end = controller.indexOf('\n public function ajax_delete_draft', start);
// Edits ride the same submit endpoint (posts_id + posts_save), which is the
// only non-draft entry point and always verifies captcha before persisting.
const start = controller.indexOf('public function ajax_submit_post(): void');
const end = controller.indexOf('\n public function ajax_save_draft', start);
const body = controller.slice(start, end);
assert.match(body, /\$action = \(\(\$data\['status'\] \?\? ''\) === 'draft'\) \? 'posts_draft' : 'posts_save';/);
assert.match(body, /if \(\$action !== 'posts_draft'\) \{\s*\$this->verify_captcha\(\);\s*\}/);
assert.match(body, /\$this->verify_nonce\(\);\s*\$this->verify_captcha\(\);\s*\$data = wp_unslash\(\$_POST\);\s*\$result = \$this->persist\(is_array\(\$data\) \? \$data : \[\], 'posts_save'\);/);
assert.match(controller, /get_error_code\(\)/);
assert.match(controller, /get_error_message\(\)/);
});