Skip to content
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
17 changes: 16 additions & 1 deletion modules/images/webp-uploads/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,22 @@ function webp_uploads_img_tag_update_mime_type( $image, $context, $attachment_id
*/
$target_mimes = apply_filters( 'webp_uploads_content_image_mimes', array( 'image/webp', 'image/jpeg' ), $attachment_id, $context );

/**
* Filters whether the smaller image should be used regardless of which MIME type is preferred overall.
*
* This is disabled by default only because it is not part of the current WordPress core feature proposal.
*
* By enabling this, the plugin will compare the image file sizes and prefer the smaller file regardless of MIME
* type.
*
* @since n.e.x.t
*
* @param bool $prefer_smaller_image_file Whether to prefer the smaller image file.
*/
if ( apply_filters( 'webp_uploads_prefer_smaller_image_file', false ) ) {
$target_mimes = webp_uploads_get_mime_types_by_filesize( $target_mimes, $attachment_id );
}

$target_mime = null;
foreach ( $target_mimes as $mime ) {
if ( isset( $metadata['sources'][ $mime ] ) ) {
Expand Down Expand Up @@ -933,4 +949,3 @@ function( $a, $b ) {
// Create an array of available mime types ordered by smallest filesize.
return array_keys( $sources );
}
add_filter( 'webp_uploads_content_image_mimes', 'webp_uploads_get_mime_types_by_filesize', 10, 2 );