| @@ -36,12 +36,11 @@ | ||
| 36 | 36 | 'type' => 'object', |
| 37 | 37 | 'properties' => [ |
| 38 | 38 | 'media_id' => [ |
| 39 | 39 | 'type' => 'integer', |
| 40 | - 'description' => __( 'The WordPress attachment ID to restore.', 'imagify' ), | |
| 40 | + 'description' => __( 'The WordPress attachment ID to restore. Provide media_filename or media_url instead when the ID is unknown.', 'imagify' ), | |
| 41 | 41 | ], |
| 42 | - ], | |
| 43 | - 'required' => [ 'media_id' ], | |
| 42 | + ] + MediaResolver::get_input_schema_properties(), | |
| 44 | 43 | ], |
| 45 | 44 | 'output_schema' => [ |
| 46 | 45 | 'type' => 'object', |
| 47 | 46 | 'properties' => [ |
| @@ -92,15 +91,15 @@ | ||
| 92 | 91 | * @param array $args Input arguments. Expects `media_id` (int) — the WordPress attachment ID. |
| 93 | 92 | * @return array{status: string, restored_size: int|null, error_message: string|null} |
| 94 | 93 | */ |
| 95 | 94 | public function execute( array $args = [] ): array { |
| 96 | - $media_id = isset( $args['media_id'] ) ? (int) $args['media_id'] : 0; | |
| 95 | + $media_id = MediaResolver::resolve_id( $args ); | |
| 97 | 96 | |
| 98 | - if ( $media_id <= 0 ) { | |
| 97 | + if ( is_wp_error( $media_id ) ) { | |
| 99 | 98 | return [ |
| 100 | 99 | 'status' => 'error', |
| 101 | 100 | 'restored_size' => null, |
| 102 | - 'error_message' => 'Invalid or missing media_id.', | |
| 101 | + 'error_message' => $media_id->get_error_message(), | |
| 103 | 102 | ]; |
| 104 | 103 | } |
| 105 | 104 | |
| 106 | 105 | $process = $this->get_process( $media_id ); |