Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter for nextgen image format #777 #783

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Changes from 2 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
27 changes: 27 additions & 0 deletions inc/common/attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,30 @@ 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 The format values. Default values are 'webp' and 'avif'.
*
* @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' );
Loading