PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
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
← All changes | inc/3rd-party/enable-media-replace/classes/Main.php +16 -26 1.10 → trunk View file →
@@ -4,10 +4,8 @@
4 4 use Imagify\Traits\InstanceGetterTrait;
5 5 use Imagify_Enable_Media_Replace_Deprecated;
6 6 use Imagify_Filesystem;
7 7
8 -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
9 -
10 8 /**
11 9 * Compat class for Enable Media Replace plugin.
12 10 *
13 11 * @since 1.6.9
@@ -39,14 +37,14 @@
39 37 */
40 38 protected $old_backup_path;
41 39
42 40 /**
43 - * List of paths to the old WebP files.
41 + * List of paths to the old next-gen files.
44 42 *
45 43 * @var array
46 44 * @since 1.9.8
47 45 */
48 - protected $old_webp_paths = [];
46 + protected $old_nextgen_paths = [];
49 47
50 48 /**
51 49 * Launch the hooks before the files and data are replaced.
52 50 *
@@ -83,31 +81,28 @@
83 81 return;
84 82 }
85 83
86 84 /**
87 - * Keep track of existing WebP files.
85 + * Keep track of existing next-gen files.
88 86 *
89 - * Whether the user chooses to rename the files or not, we will need to delete the current WebP files before creating new ones:
87 + * Whether the user chooses to rename the files or not, we will need to delete the current next-gen files before creating new ones:
90 88 * - Rename the files: the old ones must be removed, they are useless now.
91 89 * - Do not rename the files: the thumbnails may still get new names because of the suffix containing the image dimensions, which may differ (for example when thumbnails are scaled, not cropped).
92 - * In this last case, the thumbnails with the old dimensions are removed from the drive and from the WP’s post meta, so there is no need of keeping orphan WebP files that would stay on the drive for ever, even after the attachment is deleted from WP.
90 + * In this last case, the thumbnails with the old dimensions are removed from the drive and from the WP’s post meta, so there is no need of keeping orphan next-gen files that would stay on the drive for ever, even after the attachment is deleted from WP.
93 91 */
94 92 foreach ( $this->process->get_media()->get_media_files() as $media_file ) {
95 - $this->old_webp_paths[] = imagify_path_to_webp( $media_file['path'] );
93 + foreach ( [ 'avif', 'webp' ] as $format ) {
94 + $this->old_nextgen_paths[] = imagify_path_to_nextgen( $media_file['path'], $format );
95 + }
96 96 }
97 97
98 - // Delete the old backup file and old WebP files.
99 - add_action( 'imagify_before_auto_optimization', [ $this, 'delete_backup' ] );
98 + // Delete the old backup file and old next-gen files.
99 + add_action( 'imagify_before_auto_optimization', [ $this, 'delete_backup' ] );
100 100 add_action( 'imagify_not_optimized_attachment_updated', [ $this, 'delete_backup' ] );
101 101 }
102 102
103 -
104 - /** ----------------------------------------------------------------------------------------- */
105 - /** HOOKS =================================================================================== */
106 - /** ----------------------------------------------------------------------------------------- */
107 -
108 103 /**
109 - * Delete previous backup file and WebP files.
104 + * Delete previous backup file and next-gen files.
110 105 * This is done after the images have been already replaced by Enable Media Replace.
111 106 *
112 107 * @since 1.8.4
113 108 *
@@ -125,20 +120,15 @@
125 120 $filesystem->delete( $this->old_backup_path );
126 121 $this->old_backup_path = false;
127 122 }
128 123
129 - if ( ! empty( $this->old_webp_paths ) ) {
130 - // Delete old WebP files.
131 - $this->old_webp_paths = array_filter( $this->old_webp_paths, [ $filesystem, 'exists' ] );
132 - array_map( [ $filesystem, 'delete' ], $this->old_webp_paths );
133 - $this->old_webp_paths = [];
124 + if ( ! empty( $this->old_nextgen_paths ) ) {
125 + // Delete old next-gen files.
126 + $this->old_nextgen_paths = array_filter( $this->old_nextgen_paths, [ $filesystem, 'exists' ] );
127 + array_map( [ $filesystem, 'delete' ], $this->old_nextgen_paths );
128 + $this->old_nextgen_paths = [];
134 129 }
135 130 }
136 -
137 -
138 - /** ----------------------------------------------------------------------------------------- */
139 - /** TOOLS =================================================================================== */
140 - /** ----------------------------------------------------------------------------------------- */
141 131
142 132 /**
143 133 * Get the optimization process corresponding to the current media.
144 134 *