PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
← All changes | classes/Abilities/GetMediaStatus.php +26 -23 2.3.2 → trunk View file →
@@ -58,12 +58,11 @@
58 58 'type' => 'object',
59 59 'properties' => [
60 60 'media_id' => [
61 61 'type' => 'integer',
62 - 'description' => __( 'The WordPress attachment ID.', 'imagify' ),
62 + 'description' => __( 'The WordPress attachment ID. Provide media_filename or media_url instead when the ID is unknown.', 'imagify' ),
63 63 ],
64 - ],
65 - 'required' => [ 'media_id' ],
64 + ] + MediaResolver::get_input_schema_properties(),
66 65 ],
67 66 'output_schema' => [
68 67 'type' => 'object',
69 68 'properties' => [
@@ -149,33 +148,17 @@
149 148 * @param array $args Input arguments.
150 149 * @return array
151 150 */
152 151 private function do_execute( array $args ): array {
153 - $media_id = isset( $args['media_id'] ) ? (int) $args['media_id'] : 0;
152 + $media_id = MediaResolver::resolve_id( $args );
154 153
155 - if ( $media_id <= 0 ) {
156 - return [
157 - 'status' => 'error',
158 - 'error_message' => 'Invalid or missing media_id',
159 - 'optimization_level' => null,
160 - 'original_size' => 0,
161 - 'optimized_size' => 0,
162 - 'webp_available' => false,
163 - 'avif_available' => false,
164 - ];
154 + if ( is_wp_error( $media_id ) ) {
155 + return $this->error_response( $media_id->get_error_message() );
165 156 }
166 157
167 158 // Verify the attachment exists.
168 159 if ( ! get_post( $media_id ) ) {
169 - return [
170 - 'status' => 'error',
171 - 'error_message' => 'Media not found.',
172 - 'optimization_level' => null,
173 - 'original_size' => 0,
174 - 'optimized_size' => 0,
175 - 'webp_available' => false,
176 - 'avif_available' => false,
177 - ];
160 + return $this->error_response( 'Media not found.' );
178 161 }
179 162
180 163 $wp_data = $this->create_wp_data( $media_id );
181 164 $opt_data = $wp_data->get_optimization_data();
@@ -222,8 +205,28 @@
222 205 'original_size' => $original_size,
223 206 'optimized_size' => $optimized_size,
224 207 'webp_available' => $webp_available,
225 208 'avif_available' => $avif_available,
209 + 'error_message' => $error_message,
210 + ];
211 + }
212 +
213 + /**
214 + * Build an error response with every output field set to a neutral value.
215 + *
216 + * @since 2.3.3
217 + *
218 + * @param string $error_message Human-readable error message.
219 + * @return array{status: string, optimization_level: null, original_size: int, optimized_size: int, webp_available: bool, avif_available: bool, error_message: string}
220 + */
221 + private function error_response( string $error_message ): array {
222 + return [
223 + 'status' => 'error',
224 + 'optimization_level' => null,
225 + 'original_size' => 0,
226 + 'optimized_size' => 0,
227 + 'webp_available' => false,
228 + 'avif_available' => false,
226 229 'error_message' => $error_message,
227 230 ];
228 231 }
229 232