Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Avoid overwriting existing WebP files when creating WebP images #359

Merged
merged 5 commits into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/images/webp-uploads/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ function webp_uploads_generate_additional_image_source( $attachment_id, $image_s
$destination_file_name = $editor->generate_filename( null, null, $extension[0] );
}

// Skip creation of duplicate WebP image if an image file already exists in the directory.
if ( file_exists( $destination_file_name ) ) {
return new WP_Error( 'webp_image_file_present', __( 'The WebP image already exists.', 'performance-lab' ) );
}

$image = $editor->save( $destination_file_name, $mime );
if ( is_wp_error( $image ) ) {
return $image;
Expand Down