Skip to content
Prev Previous commit
Next Next commit
Updated additional mime types generation to skip image sizes that are…
… not allowed to have additional mime types.
  • Loading branch information
eugene-manuilov committed Jul 3, 2022
commit 68c37f7294878141945fedf0dc9a40b52e4b5bc2
16 changes: 12 additions & 4 deletions modules/images/webp-uploads/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ function webp_uploads_create_sources_property( array $metadata, $attachment_id )
return $metadata;
}

$sizes_with_mime_type_support = webp_uploads_get_image_sizes_with_additional_mime_type_support();

foreach ( $metadata['sizes'] as $size_name => $properties ) {
// This image size is not defined or not an array.
if ( ! is_array( $properties ) ) {
// Do nothing if this image size is not an array or is not allowed to have additional mime types.
if ( ! is_array( $properties ) || ! isset( $sizes_with_mime_type_support[ $size_name ] ) ) {
continue;
}

Expand Down Expand Up @@ -587,15 +589,21 @@ function webp_uploads_update_featured_image( $html, $post_id, $attachment_id ) {
* @return array An array of image sizes that can have additional mime types.
*/
function webp_uploads_get_image_sizes_with_additional_mime_type_support() {
$allowed_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large', 'post-thumbnail' );
$additional_sizes = wp_get_additional_image_sizes();
$allowed_sizes = array(
'thumbnail' => 'thumbnail',
'medium' => 'medium',
'medium_large' => 'medium_large',
'large' => 'large',
'post-thumbnail' => 'post-thumbnail',
);

foreach ( $additional_sizes as $size => $size_details ) {
if (
isset( $size_details['provide_additional_mime_types'] ) &&
filter_var( $size_details['provide_additional_mime_types'], FILTER_VALIDATE_BOOLEAN )
) {
$allowed_sizes[] = $size;
$allowed_sizes[ $size ] = $size;
}
}

Expand Down