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 / enable-media-replace.php

enable-media-replace.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.5, at inc/3rd-party/enable-media-replace.php

33 lines 1.0 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( 'emr_delete_current_files' ) ) :
5
6 /**
7 * Re-Optimize an attachment after replace it with Enable Media Replace.
8 *
9 * @since 1.0
10 */
11 add_action( 'enable-media-replace-upload-done', '_imagify_optimize_enable_media_replace' );
12 function _imagify_optimize_enable_media_replace( $guid ) {
13 global $wpdb;
14 $attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $guid ) );
15
16 // Stop if the attachment wasn't optimized yet by Imagify
17 if ( ! get_post_meta( $attachment_id, '_imagify_data', true ) ) {
18 return;
19 }
20
21 $optimization_level = get_post_meta( $attachment_id, '_imagify_optimization_level', true );
22
23 // Remove old optimization data
24 delete_post_meta( $attachment_id, '_imagify_data' );
25 delete_post_meta( $attachment_id, '_imagify_status' );
26 delete_post_meta( $attachment_id, '_imagify_optimization_level' );
27
28 // Optimize it!!!!!
29 $attachment = new Imagify_Attachment( $attachment_id );
30 $attachment->optimize( $optimization_level );
31 }
32
33 endif;