mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-24 23:59:07 +08:00
60 lines
1.2 KiB
PHP
60 lines
1.2 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 Add_Remediation extends Route_Base {
|
|
public string $path = 'add-remediation';
|
|
|
|
public function get_methods(): array {
|
|
return [ 'POST' ];
|
|
}
|
|
|
|
public function get_name(): string {
|
|
return 'add-remediation';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return WP_Error|WP_REST_Response
|
|
*
|
|
*/
|
|
public function POST( $request ) {
|
|
try {
|
|
$error = $this->verify_capability();
|
|
|
|
if ( $error ) {
|
|
return $error;
|
|
}
|
|
|
|
$page = $this->get_page_entry( $request->get_param( 'url' ) );
|
|
|
|
if ( ! $page ) {
|
|
return $this->respond_error_json( [
|
|
'message' => 'Missing page',
|
|
'code' => 'page_not_found',
|
|
] );
|
|
}
|
|
|
|
$page->append_remediation( $request->get_param( 'remediation' ) );
|
|
|
|
return $this->respond_success_json( [
|
|
'message' => 'Remediation added',
|
|
'data' => $page->to_json(),
|
|
] );
|
|
} catch ( Throwable $t ) {
|
|
return $this->respond_error_json( [
|
|
'message' => $t->getMessage(),
|
|
'code' => 'internal_server_error',
|
|
] );
|
|
}
|
|
}
|
|
}
|