wp-media / imagify-plugin

Speed up your website with lighter images without losing quality.
https://imagify.io
69 stars 24 forks source link

Add filter for nextgen image format #777 #783

Closed Khadreal closed 5 months ago

Khadreal commented 5 months ago

Description

Add imagify_nextgen_images_formats filter

Fixes #777

Type of change

Is the solution different from the one proposed during the grooming?

No

Checklists

Generic development checklist

Test summary

jeawhanlee commented 5 months ago

@Tabrisrp This PR is dependent on this: https://github.com/wp-media/imagify-plugin/pull/782 no?

Khadreal commented 5 months ago

@Tabrisrp This PR is dependent on this: #782 no?

To the best of my knowledge, no

Khadreal commented 5 months ago

This is how I was picturing it so that we can re-use the function whenever we need:

function imagify_nextgen_images_formats() {
    $formats = [
        'webp',
    ];

    if ( get_imagify_option( 'convert_to_avif' ) ) {
        $formats[] = 'avif';
    }

    $default = $formats;
    /**
     * Filters the array of next gen formats to generate with Imagify
     *
     * @since 2.2
     *
     * @param array $formats Array of image formats
     */
    $formats = apply_filters( 'imagify_nextgen_images_formats', $formats );

    if ( ! is_array( $formats ) ) {
        $formats = $default;
    }

    return $formats;
}

Cool! I was thinking we would use filter in place of calling the function.