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

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

55 lines 1.5 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 /**
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 * Delete the backup file when an attachement is deleted.
25 *
26 * @since 1.0
27 */
28 add_action( 'delete_attachment', '_imagify_delete_backup_file' );
29 function _imagify_delete_backup_file( $post_id ) {
30 $attachment = new Imagify_Attachment( $post_id );
31 $attachment->delete_backup();
32 }
33
34 /**
35 * Optimize a resized attachment
36 *
37 * @since 1.3.6
38 * @since 1.4 Async job
39 */
40 add_action( 'shutdown', '_imagify_optimize_save_image_editor_file' );
41 function _imagify_optimize_save_image_editor_file() {
42 if ( isset( $_POST['action'], $_POST['do'], $_POST['postid'] )
43 && 'image-editor' === $_POST['action']
44 && check_ajax_referer( 'image_editor-' . $_POST['postid'] )
45 && get_post_meta( $_POST['postid'], '_imagify_data', true )
46 && 'open' != $_POST['do']
47 ) {
48
49 $body = $_POST;
50 $body['action'] = 'imagify_async_optimize_save_image_editor_file';
51 $body['transient_id'] = $body['postid'];
52
53 imagify_do_async_job( $body );
54 }
55 }