PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.3.3
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.3.3
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 / common / attachments.php

attachments.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.3.3, at inc/common/attachments.php

33 lines 868 B
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 /**
5 * Auto-optimize when a new attachment is generated
6 *
7 * @since 1.0
8 */
9 add_filter( 'wp_generate_attachment_metadata', '_imagify_optimize_attachment', PHP_INT_MAX, 2 );
10 function _imagify_optimize_attachment( $metadata, $attachment_id ) {
11 $api_key = get_imagify_option( 'api_key', false );
12
13 if ( ! empty( $api_key ) && get_imagify_option( 'auto_optimize', false ) ) {
14 $attachment = new Imagify_Attachment( $attachment_id );
15
16 // Optimize it!!!!!
17 $attachment->optimize( null, $metadata );
18 }
19
20 return $metadata;
21 }
22
23
24 /**
25 * Delete the backup file when an attachement is deleted.
26 *
27 * @since 1.0
28 */
29 add_action( 'delete_attachment', '_imagify_delete_backup_file' );
30 function _imagify_delete_backup_file( $post_id ) {
31 $attachment = new Imagify_Attachment( $post_id );
32 $attachment->delete_backup();
33 }