PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.1
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.1
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 2.3.1, at inc/common/attachments.php

102 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
3
4 add_action( 'delete_attachment', 'imagify_trigger_delete_attachment_hook' );
5 /**
6 * Trigger a common Imagify hook when an attachment is deleted.
7 *
8 * @since 1.9
9 * @author Grégory Viguier
10 *
11 * @param int $post_id Attachment ID.
12 */
13 function imagify_trigger_delete_attachment_hook( $post_id ) {
14 $process = imagify_get_optimization_process( $post_id, 'wp' );
15
16 if ( ! $process->is_valid() ) {
17 return;
18 }
19
20 imagify_trigger_delete_media_hook( $process );
21 }
22
23 add_action( 'imagify_delete_media', 'imagify_cleanup_after_media_deletion' );
24 /**
25 * Delete the backup file and the next-gen files when an attachement is deleted.
26 *
27 * @since 1.9
28 * @author Grégory Viguier
29 *
30 * @param ProcessInterface $process An optimization process.
31 */
32 function imagify_cleanup_after_media_deletion( $process ) {
33 if ( 'wp' !== $process->get_media()->get_context() ) {
34 return;
35 }
36
37 /**
38 * The optimization data will be automatically deleted by WP (post metas).
39 * Delete the Nextgen versions and the backup file.
40 */
41 $process->delete_nextgen_files( false, true );
42
43 $process->delete_backup();
44 }
45
46 add_filter( 'ext2type', 'imagify_add_avif_type' );
47 /**
48 * Add the AVIF extension to wp_get_ext_types().
49 *
50 * @since 1.9
51 * @author Grégory Viguier
52 *
53 * @param array $ext2type Multi-dimensional array with extensions for a default set of file types.
54 * @return array
55 */
56 function imagify_add_avif_type( $ext2type ) {
57 if ( ! in_array( 'avif', $ext2type['image'], true ) ) {
58 $ext2type['image'][] = 'avif';
59 }
60 return $ext2type;
61 }
62
63 /**
64 * Set WP’s "big images threshold" to Imagify’s resizing value.
65 *
66 * @since 1.9.8
67 * @since WP 5.3
68 * @author Grégory Viguier
69 */
70 add_filter( 'big_image_size_threshold', [ imagify_get_context( 'wp' ), 'get_resizing_threshold' ], IMAGIFY_INT_MAX );
71
72 /**
73 * Add filters to manage images formats that will be generated
74 *
75 * @return array
76 */
77 function imagify_nextgen_images_formats() {
78 $value = get_imagify_option( 'optimization_format' );
79 $formats = [];
80
81 if ( 'off' !== $value ) {
82 $formats[ $value ] = $value;
83 }
84
85 $default = $formats;
86
87 /**
88 * Filters the array of next gen formats to generate with Imagify
89 *
90 * @since 2.2
91 *
92 * @param array $formats Array of image formats
93 */
94 $formats = apply_filters( 'imagify_nextgen_images_formats', $formats );
95
96 if ( ! is_array( $formats ) ) {
97 $formats = $default;
98 }
99
100 return $formats;
101 }
102