@@ -63,7 +63,7 @@ public function executeTask( int $jobId, array $params ): void {
6363
6464 $ file_path = get_attached_file ( $ attachment_id );
6565 if ( empty ( $ file_path ) || ! file_exists ( $ file_path ) ) {
66- $ this ->failJob ( $ jobId , 'Attachment file not found: ' . ( $ file_path ?: 'empty path ' ) );
66+ $ this ->failJob ( $ jobId , 'Attachment file not found: ' . ( $ file_path ? $ file_path : 'empty path ' ) );
6767 return ;
6868 }
6969
@@ -138,18 +138,27 @@ private function compressImage( string $file_path, string $mime_type, int $quali
138138 $ editor = wp_get_image_editor ( $ file_path );
139139
140140 if ( is_wp_error ( $ editor ) ) {
141- return array ( 'success ' => false , 'error ' => 'Image editor not available: ' . $ editor ->get_error_message () );
141+ return array (
142+ 'success ' => false ,
143+ 'error ' => 'Image editor not available: ' . $ editor ->get_error_message (),
144+ );
142145 }
143146
144147 $ editor ->set_quality ( $ quality );
145148 $ saved = $ editor ->save ( $ file_path , $ mime_type );
146149
147150 if ( is_wp_error ( $ saved ) ) {
148- return array ( 'success ' => false , 'error ' => 'Compression failed: ' . $ saved ->get_error_message () );
151+ return array (
152+ 'success ' => false ,
153+ 'error ' => 'Compression failed: ' . $ saved ->get_error_message (),
154+ );
149155 }
150156
151157 clearstatcache ( true , $ file_path );
152- return array ( 'success ' => true , 'new_size ' => filesize ( $ file_path ) );
158+ return array (
159+ 'success ' => true ,
160+ 'new_size ' => filesize ( $ file_path ),
161+ );
153162 }
154163
155164 /**
@@ -162,21 +171,35 @@ private function generateWebP( string $file_path, int $quality, int $attachment_
162171 $ webp_path = preg_replace ( '/\.(jpe?g|png)$/i ' , '.webp ' , $ file_path );
163172
164173 if ( file_exists ( $ webp_path ) ) {
165- return array ( 'success ' => true , 'webp_path ' => $ webp_path , 'webp_size ' => filesize ( $ webp_path ) );
174+ return array (
175+ 'success ' => true ,
176+ 'webp_path ' => $ webp_path ,
177+ 'webp_size ' => filesize ( $ webp_path ),
178+ );
166179 }
167180
168181 $ editor = wp_get_image_editor ( $ file_path );
169182 if ( is_wp_error ( $ editor ) ) {
170- return array ( 'success ' => false , 'error ' => 'Image editor not available: ' . $ editor ->get_error_message () );
183+ return array (
184+ 'success ' => false ,
185+ 'error ' => 'Image editor not available: ' . $ editor ->get_error_message (),
186+ );
171187 }
172188
173189 $ editor ->set_quality ( $ quality );
174190 $ saved = $ editor ->save ( $ webp_path , 'image/webp ' );
175191
176192 if ( is_wp_error ( $ saved ) ) {
177- return array ( 'success ' => false , 'error ' => 'WebP generation failed: ' . $ saved ->get_error_message () );
193+ return array (
194+ 'success ' => false ,
195+ 'error ' => 'WebP generation failed: ' . $ saved ->get_error_message (),
196+ );
178197 }
179198
180- return array ( 'success ' => true , 'webp_path ' => $ saved ['path ' ], 'webp_size ' => filesize ( $ saved ['path ' ] ) );
199+ return array (
200+ 'success ' => true ,
201+ 'webp_path ' => $ saved ['path ' ],
202+ 'webp_size ' => filesize ( $ saved ['path ' ] ),
203+ );
181204 }
182205}
0 commit comments