@@ -179,14 +179,15 @@ public function get_design_library_image( $request ) {
179179 if ( is_wp_error ( $ temp_filepath ) ) {
180180 return new WP_REST_Response ( array (
181181 'success ' => false ,
182- 'message ' => ' Failed to retrieve image from the provided URL. '
182+ 'message ' => $ temp_filepath -> get_error_message ()
183183 ), 500 );
184184 }
185185
186186 if ( ! file_exists ( $ temp_filepath ) || ! wp_filesize ( $ temp_filepath ) ) {
187- @ unlink ( $ temp_filepath );
187+ wp_delete_file ( $ temp_filepath );
188188 return new WP_REST_Response ( array (
189189 'success ' => false ,
190+ // This is a custom check so we return a custom error message.
190191 'message ' => 'Invalid file content retrieved from the provided URL. '
191192 ), 400 );
192193 }
@@ -205,9 +206,10 @@ public function get_design_library_image( $request ) {
205206 && ! wp_getimagesize ( $ temp_filepath )
206207 )
207208 ) {
208- @ unlink ( $ temp_filepath );
209+ wp_delete_file ( $ temp_filepath );
209210 return new WP_REST_Response ( array (
210211 'success ' => false ,
212+ // This is a custom check so we return a custom error message.
211213 'message ' => 'The file is not a valid image/video. '
212214 ), 400 );
213215 }
@@ -219,13 +221,13 @@ public function get_design_library_image( $request ) {
219221 ) );
220222
221223 if ( file_exists ( $ temp_filepath ) ) {
222- @ unlink ( $ temp_filepath );
224+ wp_delete_file ( $ temp_filepath );
223225 }
224226
225227 if ( is_wp_error ( $ media_id ) ) {
226228 return new WP_REST_Response ( array (
227229 'success ' => false ,
228- 'message ' => ' An error occured during media upload. '
230+ 'message ' => $ media_id -> get_error_message ()
229231 ), 500 );
230232 }
231233
0 commit comments