@@ -38,8 +38,9 @@ function webp_uploads_create_sources_property( array $metadata, $attachment_id,
3838 return $ metadata ;
3939 }
4040
41- $ is_update = 'update ' === $ context ;
42- $ target = isset ( $ _REQUEST ['target ' ] ) ? $ _REQUEST ['target ' ] : 'all ' ;
41+ $ is_update = 'update ' === $ context ;
42+ $ target = isset ( $ _REQUEST ['target ' ] ) ? $ _REQUEST ['target ' ] : 'all ' ;
43+ $ attached_file = get_attached_file ( $ attachment_id , true );
4344 if ( $ is_update ) {
4445 if ( empty ( $ metadata ['file ' ] ) ) {
4546 return $ metadata ;
@@ -51,7 +52,7 @@ function webp_uploads_create_sources_property( array $metadata, $attachment_id,
5152 return $ metadata ;
5253 }
5354 } else {
54- $ file = get_attached_file ( $ attachment_id , true ) ;
55+ $ file = $ attached_file ;
5556 }
5657
5758 // File does not exist and we are not editing only the thumbnail.
@@ -125,11 +126,16 @@ function webp_uploads_create_sources_property( array $metadata, $attachment_id,
125126 }
126127
127128 foreach ( $ metadata ['sizes ' ] as $ size_name => $ properties ) {
128-
129+ // WHen only the thumbnail is selected to be edited any other size is dismissed.
129130 if ( 'thumbnail ' === $ target && 'thumbnail ' !== $ size_name ) {
130131 continue ;
131132 }
132133
134+ // When all the sizes except the thumbnail are edited the thumbnail is dismissed.
135+ if ( 'nothumb ' === $ target && 'thumbnail ' === $ size_name ) {
136+ continue ;
137+ }
138+
133139 // This image size is not defined or not an array.
134140 if ( ! is_array ( $ properties ) ) {
135141 continue ;
@@ -177,19 +183,23 @@ function webp_uploads_create_sources_property( array $metadata, $attachment_id,
177183 continue ;
178184 }
179185
180- if ( 'update ' === $ context && 'thumbnail ' === $ target ) {
181- /**
182- * When only the thumbnail requires additional image, make sure that the base image to create additional
183- * mime types is the thumbnail with the original mime type due this image is the only one that was modified
184- * using the attached image or original image would be. The filename should match the original image with
185- * the only difference of the extension on the filename instead, so the new created image does not have multiple
186- * suffix like filename-150x150-150x150.webp and instead matches filename-150x150.webp
187- */
188- $ original_extension = explode ( '| ' , $ allowed_mimes [ $ current_mime ] );
189- $ target_extension = explode ( '| ' , $ allowed_mimes [ $ mime ] );
190- $ file_path = path_join ( $ original_directory , $ properties ['file ' ] );
191- $ destination = preg_replace ( "/\. {$ original_extension [0 ]}$/ " , ". {$ target_extension [0 ]}" , $ file_path );
192- $ source = webp_uploads_generate_image_size ( $ attachment_id , $ size_name , $ mime , $ file_path , $ destination );
186+ if ( 'update ' === $ context ) {
187+ if ( 'thumbnail ' === $ target ) {
188+ /**
189+ * When only the thumbnail requires additional image, make sure that the base image to create additional
190+ * mime types is the thumbnail with the original mime type due this image is the only one that was modified
191+ * using the attached image or original image would be. The filename should match the original image with
192+ * the only difference of the extension on the filename instead, so the new created image does not have multiple
193+ * suffix like filename-150x150-150x150.webp and instead matches filename-150x150.webp
194+ */
195+ $ original_extension = explode ( '| ' , $ allowed_mimes [ $ current_mime ] );
196+ $ target_extension = explode ( '| ' , $ allowed_mimes [ $ mime ] );
197+ $ file_path = path_join ( $ original_directory , $ properties ['file ' ] );
198+ $ destination = preg_replace ( "/\. {$ original_extension [0 ]}$/ " , ". {$ target_extension [0 ]}" , $ file_path );
199+ $ source = webp_uploads_generate_image_size ( $ attachment_id , $ size_name , $ mime , $ file_path , $ destination );
200+ } else {
201+ $ source = webp_uploads_generate_image_size ( $ attachment_id , $ size_name , $ mime , $ attached_file );
202+ }
193203 } else {
194204 $ source = webp_uploads_generate_image_size ( $ attachment_id , $ size_name , $ mime );
195205 }
0 commit comments