Skip to content

Commit

Permalink
Closes #796: Add the -scaled version to backup so we can convert it
Browse files Browse the repository at this point in the history
  • Loading branch information
Miraeld committed Feb 23, 2024
1 parent 2dbf2e8 commit cf05128
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions classes/Optimization/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,22 @@ public function backup( $backup_path = null, $backup_source = null ) {
) );
}

// Check if a '-scaled' version of the image exists.
$scaled_path = preg_replace('/(\.)([^\.]+)$/', '-scaled.$2', $backup_source);
if ($this->filesystem->exists($scaled_path)) {
// Create a backup path for the scaled image.
$scaled_backup_path = preg_replace('/(\.)([^\.]+)$/', '-scaled.$2', $backup_path);
// Copy the '-scaled' version to the backup.
$this->filesystem->copy( $scaled_path, $scaled_backup_path, $overwrite, FS_CHMOD_FILE );

if ( ! $this->filesystem->exists( $scaled_backup_path ) ) {
return new \WP_Error( 'backup_doesnt_exist', __( 'The file could not be saved.', 'imagify' ), array(
'file_path' => $this->filesystem->make_path_relative( $scaled_path ),
'backup_path' => $this->filesystem->make_path_relative( $scaled_backup_path ),
) );
}
}

return true;
}

Expand Down

0 comments on commit cf05128

Please sign in to comment.