one-click-accessibility/modules/remediation/rest/dismiss-heading-issue.php
VasylD ad2174ffe3
[APP-1792] Add headings structure (#406)
* New: Add the heading structure components [APP-1792] (#391)

* New: Add the new rules [APP-1792]

* New: Add the BE integration [APP-1792]

* Fix: Fix QA issues [APP-1792]

* merge latest dev

* merge latest dev

* merge latest dev

* merge latest dev

* merge latest dev

* merge latest dev

* add reset to initial

---------

Co-authored-by: Pavlo Kniazevych <139438463+pkniazevych@users.noreply.github.com>
Co-authored-by: Kniazevych <pavlok@elementor.red>
2025-09-24 09:47:57 +02:00

69 lines
1.4 KiB
PHP

<?php
namespace EA11y\Modules\Remediation\Rest;
use EA11y\Modules\Remediation\Classes\Route_Base;
use Throwable;
use WP_Error;
use WP_REST_Response;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Dismiss_Heading_Issue extends Route_Base {
const META_KEY = 'ea11y-scanner-heading-issues-dismissed';
public string $path = 'dismiss-heading-issue';
public function get_methods(): array {
return [ 'POST' ];
}
public function get_name(): string {
return 'dismiss-heading-issue';
}
/**
*
* @return WP_Error|WP_REST_Response
*
*/
public function POST( $request ) {
try {
$error = $this->verify_capability();
if ( $error ) {
return $error;
}
$post_id = (int) sanitize_text_field( $request->get_param( 'pageId' ) );
$xpath = sanitize_text_field( $request->get_param( 'xpath' ) );
if ( ! $post_id || ! $xpath ) {
return $this->respond_error_json( [
'message' => 'Missing required parameters',
'code' => 'missing_parameters',
] );
}
$data = get_post_meta( $post_id, self::META_KEY, true ) ?? [];
if ( ! $data ) {
$data = [];
}
$data[] = $xpath;
update_post_meta( $post_id, self::META_KEY, array_unique( $data ) );
return $this->respond_success_json( [
'message' => 'Heading issue dismissed',
] );
} catch ( Throwable $t ) {
return $this->respond_error_json( [
'message' => $t->getMessage(),
'code' => 'internal_server_error',
] );
}
}
}