diff --git a/inc/common/attachments.php b/inc/common/attachments.php index b58f070e7..4f6e13a2a 100755 --- a/inc/common/attachments.php +++ b/inc/common/attachments.php @@ -67,3 +67,29 @@ function imagify_add_webp_type( $ext2type ) { * @author Grégory Viguier */ add_filter( 'big_image_size_threshold', [ imagify_get_context( 'wp' ), 'get_resizing_threshold' ], IMAGIFY_INT_MAX ); + +/** + * Add filters to manage images formats that will be generated + * + * @param array $formats + * + * @return array; + */ +function imagify_nextgen_images_format( array $formats ) { + //If no formats is passed, bail early and default to webp. + if ( empty( $formats) ) { + return ['webp']; + } + + if ( isset( $formats['webp'], $formats['avif'] ) + && ( $formats['avif'] && $formats['webp'] ) + ) { + return ['avif', 'webp']; + } + + return $formats; +} +/** + * Filter to get the image format to generate. +*/ +add_filter( 'imagify_nextgen_images_formats', 'imagify_nextgen_images_format' );