From e11a6afbba1adb5a25a815440007cb99c5bb5cfb Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Fri, 10 Jun 2022 11:43:33 +0530 Subject: [PATCH 1/5] Skip creation of duplicate WebP images --- modules/images/webp-uploads/load.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/images/webp-uploads/load.php b/modules/images/webp-uploads/load.php index 8a2b9c409d..9704e4c519 100644 --- a/modules/images/webp-uploads/load.php +++ b/modules/images/webp-uploads/load.php @@ -90,6 +90,12 @@ function webp_uploads_create_sources_property( array $metadata, $attachment_id ) $extension = explode( '|', $allowed_mimes[ $targeted_mime ] ); $destination = trailingslashit( $original_directory ) . "{$filename}.{$extension[0]}"; + + // Skip creation of duplicate WebP image if a image file has the same name with an extension of jpe, jpg, or jpeg. + if ( file_exists( $destination ) ) { + continue; + } + $image = webp_uploads_generate_additional_image_source( $attachment_id, 'full', $original_size_data, $targeted_mime, $destination ); if ( is_wp_error( $image ) ) { From 79d153325dbdb5b3d3279704a13b8a3067687bba Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Fri, 10 Jun 2022 12:06:39 +0530 Subject: [PATCH 2/5] Fix PHP lint --- modules/images/webp-uploads/load.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/images/webp-uploads/load.php b/modules/images/webp-uploads/load.php index 9704e4c519..e23519afc7 100644 --- a/modules/images/webp-uploads/load.php +++ b/modules/images/webp-uploads/load.php @@ -90,13 +90,13 @@ function webp_uploads_create_sources_property( array $metadata, $attachment_id ) $extension = explode( '|', $allowed_mimes[ $targeted_mime ] ); $destination = trailingslashit( $original_directory ) . "{$filename}.{$extension[0]}"; - + // Skip creation of duplicate WebP image if a image file has the same name with an extension of jpe, jpg, or jpeg. if ( file_exists( $destination ) ) { continue; } - $image = webp_uploads_generate_additional_image_source( $attachment_id, 'full', $original_size_data, $targeted_mime, $destination ); + $image = webp_uploads_generate_additional_image_source( $attachment_id, 'full', $original_size_data, $targeted_mime, $destination ); if ( is_wp_error( $image ) ) { continue; From 9c710f50bdfc1d12e1d126d7eba6e66edaab60c6 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 15 Jun 2022 09:20:39 +0530 Subject: [PATCH 3/5] Revert changes. Changes are reverted and working on other approach. --- modules/images/webp-uploads/load.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/modules/images/webp-uploads/load.php b/modules/images/webp-uploads/load.php index e23519afc7..8a2b9c409d 100644 --- a/modules/images/webp-uploads/load.php +++ b/modules/images/webp-uploads/load.php @@ -90,13 +90,7 @@ function webp_uploads_create_sources_property( array $metadata, $attachment_id ) $extension = explode( '|', $allowed_mimes[ $targeted_mime ] ); $destination = trailingslashit( $original_directory ) . "{$filename}.{$extension[0]}"; - - // Skip creation of duplicate WebP image if a image file has the same name with an extension of jpe, jpg, or jpeg. - if ( file_exists( $destination ) ) { - continue; - } - - $image = webp_uploads_generate_additional_image_source( $attachment_id, 'full', $original_size_data, $targeted_mime, $destination ); + $image = webp_uploads_generate_additional_image_source( $attachment_id, 'full', $original_size_data, $targeted_mime, $destination ); if ( is_wp_error( $image ) ) { continue; From 71c62f6b4367fc21177ef54b804a869d2e0fadb6 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 15 Jun 2022 09:24:26 +0530 Subject: [PATCH 4/5] Update helper.php // Skip creation of duplicate WebP image if an image file already exists in the directory. --- modules/images/webp-uploads/helper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/images/webp-uploads/helper.php b/modules/images/webp-uploads/helper.php index 4bb8bc1d87..0eca48ba00 100644 --- a/modules/images/webp-uploads/helper.php +++ b/modules/images/webp-uploads/helper.php @@ -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; From e6ff5232ff5cfbc813960b9775e92200fea465c6 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 16 Jun 2022 09:20:01 +0530 Subject: [PATCH 5/5] Text updated --- modules/images/webp-uploads/helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/images/webp-uploads/helper.php b/modules/images/webp-uploads/helper.php index 0eca48ba00..bd720c32d5 100644 --- a/modules/images/webp-uploads/helper.php +++ b/modules/images/webp-uploads/helper.php @@ -144,7 +144,7 @@ function webp_uploads_generate_additional_image_source( $attachment_id, $image_s // 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' ) ); + return new WP_Error( 'webp_image_file_present', __( 'The WebP image already exists.', 'performance-lab' ) ); } $image = $editor->save( $destination_file_name, $mime );