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:
1 parent
5fbcfa2b49
commit
d84d485ec7
2 files changed
+5
-24
No files matched your search
@@ -30,7 +30,6 @@ class FrontSubmit {
|
|||||||
public function init(): void {
|
public function init(): void {
|
||||||
add_action('wp_ajax_aksrt_submit_post', [$this, 'ajax_submit_post']);
|
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_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_draft', [$this, 'ajax_delete_draft']);
|
||||||
add_action('wp_ajax_aksrt_delete_post', [$this, 'ajax_delete_post']);
|
add_action('wp_ajax_aksrt_delete_post', [$this, 'ajax_delete_post']);
|
||||||
|
|
||||||
@@ -383,25 +382,6 @@ class FrontSubmit {
|
|||||||
$this->send_result($result);
|
$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 {
|
public function ajax_delete_draft(): void {
|
||||||
$this->verify_nonce();
|
$this->verify_nonce();
|
||||||
$user_id = get_current_user_id();
|
$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', () => {
|
test('non-draft front-submit updates require one server captcha admission', () => {
|
||||||
const controller = read('src/Core/FrontSubmit.php');
|
const controller = read('src/Core/FrontSubmit.php');
|
||||||
const start = controller.indexOf('public function ajax_update_post(): void');
|
// Edits ride the same submit endpoint (posts_id + posts_save), which is the
|
||||||
const end = controller.indexOf('\n public function ajax_delete_draft', start);
|
// 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);
|
const body = controller.slice(start, end);
|
||||||
|
|
||||||
assert.match(body, /\$action = \(\(\$data\['status'\] \?\? ''\) === 'draft'\) \? 'posts_draft' : 'posts_save';/);
|
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(body, /if \(\$action !== 'posts_draft'\) \{\s*\$this->verify_captcha\(\);\s*\}/);
|
|
||||||
assert.match(controller, /get_error_code\(\)/);
|
assert.match(controller, /get_error_code\(\)/);
|
||||||
assert.match(controller, /get_error_message\(\)/);
|
assert.match(controller, /get_error_message\(\)/);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user