Skip to content

Commit

Permalink
Fixes #815 Skip image deletion if returned path value is false (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
remyperona authored Feb 27, 2024
1 parent a62dc23 commit e357b67
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions classes/Optimization/Process/AbstractProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -1436,8 +1436,9 @@ public function delete_nextgen_files( $keep_full = false ) {
*
* @since 2.2
*
* @param string $file_path Path to the non-next-gen file.
* @return void|WP_Error A \WP_Error object on failure.
* @param string $file_path Path to the non-next-gen file.
*
* @return void|WP_Error A WP_Error object on failure.
*/
protected function delete_nextgen_file( $file_path ) {
if ( ! $file_path ) {
Expand All @@ -1448,18 +1449,25 @@ protected function delete_nextgen_file( $file_path ) {

// Delete next-gen images.
foreach ( $this->extensions as $extension ) {
$this->delete_file( $next_gen_file->get_path_to_nextgen( $extension ) );
$path = $next_gen_file->get_path_to_nextgen( $extension );

if ( ! $path ) {
continue;
}

$this->delete_file( $path );
}
}

/**
* Delete a next gen format image, given its non-next-gen version's path.
*
* @param string $next_gen_path Path to the non-next-gen file.
* @return bool|WP_Error True on success. A \WP_Error object on failure.
*
* @return bool|WP_Error True on success. A WP_Error object on failure.
*/
protected function delete_file( string $next_gen_path ) {
if ( ! $next_gen_path ) {
if ( empty( $next_gen_path ) ) {
return new WP_Error( 'no_$next_gen_path', __( 'Could not get the path to the Next-Gen format file.', 'imagify' ) );
}

Expand Down

0 comments on commit e357b67

Please sign in to comment.