PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.5
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.5
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / 3rd-party / wp-retina-2x.php

wp-retina-2x.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.5, at inc/3rd-party/wp-retina-2x.php

58 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3
4 if ( function_exists( 'wr2x_delete_attachment' ) && function_exists( 'wr2x_generate_images' ) ) :
5
6 /**
7 * Process to restore all retina versions for an attachment
8 *
9 * @since 1.0
10 */
11 add_action( 'before_imagify_restore_attachment', '_imagify_wr2x_delete_attachment_on_restore' );
12 function _imagify_wr2x_delete_attachment_on_restore( $attachment_id ) {
13 // Remove all retina versions if exists
14 wr2x_delete_attachment( $attachment_id );
15 }
16
17 add_action( 'after_imagify_restore_attachment', '_imagify_wr2x_generate_images_on_restore' );
18 function _imagify_wr2x_generate_images_on_restore( $attachment_id ) {
19 // Regenerate all retina versions
20 $metadata = wp_get_attachment_metadata( $attachment_id );
21 wr2x_generate_images( $metadata );
22 }
23
24 endif;
25
26 if ( function_exists( 'wr2x_get_retina' ) ) :
27
28 /**
29 * Process to generate the retina version of a thumbnail
30 *
31 * @since 1.0
32 */
33 add_filter( 'imagify_fill_thumbnail_data', '_imagify_optimize_wr2x', 10, 7 );
34 function _imagify_optimize_wr2x( $data, $response, $id, $path, $url, $size_key, $optimization_level ) {
35 /**
36 * Allow to optimize the retina version generated by WP Retina x2
37 *
38 * @since 1.0
39 *
40 * @param bool true will force the optimization
41 */
42 $do_retina = apply_filters( 'do_imagify_optimize_retina', true );
43
44 $retina_path = wr2x_get_retina( $path );
45
46 if ( ! empty( $retina_path ) && $do_retina ) {
47 $response = do_imagify( $retina_path, array(
48 'backup' => false,
49 'optimization_level' => $optimization_level,
50 'context' => 'wp-retina'
51 ) );
52 $data = Imagify_Attachment::fill_data( $data, $response, $id, $url, $size_key . '@2x' );
53 }
54
55 return $data;
56 }
57
58 endif;