Skip to content

Commit

Permalink
fix: api save
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Apr 15, 2024
1 parent 8637991 commit 7597e32
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions includes/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
use WP_Error;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;

class Api {
public function register_routes(): void {
register_rest_route(
'acpl',
'/ai-alt-generator',
[
'methods' => 'POST',
'methods' => WP_REST_Server::CREATABLE,
'args' => [
'attachment_id' => [
'required' => true,
'type' => 'integer',
],
'save_alt' => [
'required' => false,
'type' => 'boolean',
'default' => false,
'save' => [
'required' => false,
'type' => 'boolean',
'default' => false,
'description' => esc_html__( 'Saves the generated alt text to the image when enabled.', 'alt-text-generator-gpt-vision' ),
],
],
'callback' => [ $this, 'generate_alt_text' ],
Expand All @@ -32,7 +34,7 @@ public function register_routes(): void {

public function generate_alt_text( WP_REST_Request $request ): WP_REST_Response|WP_Error {
$attachment_id = $request->get_param( 'attachment_id' );
$save_alt = $request->get_param( 'save_alt' );
$save_alt = $request->get_param( 'save' );

if ( $save_alt ) {
$alt_text = AltGenerator::generate_and_set_alt_text( $attachment_id );
Expand Down

0 comments on commit 7597e32

Please sign in to comment.