mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-23 20:00:51 +08:00
* [APP-934] add submit logic * [APP-934] add submit logic * [APP-934] add submit logic * [APP-934] add submit logic * Added replace remediation action * Add submit logic * Add submit alt text logic, generate AI alt text * Add AI generate request, add convert from SVG to png base64, added manual fix block * Add AI generate request, add convert from SVG to png base64, added manual fix block * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation --------- Co-authored-by: Raz Ohad <admin@bainternet.info>
70 lines
1.5 KiB
PHP
70 lines
1.5 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 Set_Alt_Text extends Route_Base {
|
|
const ALT_TEXT_META_KEY = '_wp_attachment_image_alt';
|
|
public string $path = 'set-alt-text';
|
|
|
|
public function get_methods(): array {
|
|
return [ 'POST' ];
|
|
}
|
|
|
|
public function get_name(): string {
|
|
return 'set-alt-text';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return WP_Error|WP_REST_Response
|
|
*
|
|
*/
|
|
public function POST( $request ) {
|
|
try {
|
|
$error = $this->verify_capability();
|
|
|
|
if ( $error ) {
|
|
return $error;
|
|
}
|
|
|
|
$url = esc_url_raw( $request->get_param( 'url' ) );
|
|
$alt_text = sanitize_text_field( $request->get_param( 'alt_text' ) );
|
|
|
|
if ( ! $url ) {
|
|
return $this->respond_error_json( [
|
|
'message' => 'Missing required parameters',
|
|
'code' => 'missing_parameters',
|
|
] );
|
|
}
|
|
|
|
$attachment_id = attachment_url_to_postid( $url );
|
|
$attachment = get_post( $attachment_id );
|
|
if ( ! $attachment ) {
|
|
return $this->respond_error_json( [
|
|
'message' => 'Attachment not found',
|
|
'code' => 'attachment_not_found',
|
|
] );
|
|
}
|
|
|
|
update_post_meta( $attachment_id, self::ALT_TEXT_META_KEY, $alt_text );
|
|
|
|
return $this->respond_success_json( [
|
|
'message' => 'Alt text updated',
|
|
] );
|
|
} catch ( Throwable $t ) {
|
|
return $this->respond_error_json( [
|
|
'message' => $t->getMessage(),
|
|
'code' => 'internal_server_error',
|
|
] );
|
|
}
|
|
}
|
|
}
|