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 | classes/Optimization/Process/ProcessInterface.php +102 -145 1.10 → trunk View file →
@@ -1,26 +1,44 @@
1 1 <?php
2 +declare(strict_types=1);
3 +
2 4 namespace Imagify\Optimization\Process;
3 5
4 -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
6 +use Imagify\Media\MediaInterface;
7 +use Imagify\Optimization\Data\DataInterface;
8 +use Imagify\Optimization\File;
9 +use WP_Error;
5 10
6 11 /**
7 12 * Interface to use to optimize medias.
8 13 *
9 - * @since 1.9
10 - * @author Grégory Viguier
14 + * @since 1.9
11 15 */
12 16 interface ProcessInterface {
17 + /**
18 + * The suffix used in the thumbnail size name.
19 + *
20 + * @var string
21 + * @since 1.9
22 + */
23 + const WEBP_SUFFIX = '@imagify-webp';
13 24
14 25 /**
26 + * The suffix used in the thumbnail size name.
27 + *
28 + * @var string
29 + * @since 2.2
30 + */
31 + const AVIF_SUFFIX = '@imagify-avif';
32 +
33 + /**
15 34 * Tell if the given entry can be accepted in the constructor.
16 35 * For example it can include `is_numeric( $id )` if the constructor accepts integers.
17 36 *
18 - * @since 1.9
19 - * @access public
20 - * @author Grégory Viguier
37 + * @since 1.9
21 38 *
22 - * @param mixed $id Whatever.
39 + * @param mixed $id Whatever.
40 + *
23 41 * @return bool
24 42 */
25 43 public static function constructor_accepts( $id );
26 44
@@ -26,11 +44,9 @@
26 44
27 45 /**
28 46 * Get the data instance.
29 47 *
30 - * @since 1.9
31 - * @access public
32 - * @author Grégory Viguier
48 + * @since 1.9
33 49 *
34 50 * @return DataInterface|false
35 51 */
36 52 public function get_data();
@@ -37,11 +53,9 @@
37 53
38 54 /**
39 55 * Get the media instance.
40 56 *
41 - * @since 1.9
42 - * @access public
43 - * @author Grégory Viguier
57 + * @since 1.9
44 58 *
45 59 * @return MediaInterface|false
46 60 */
47 61 public function get_media();
@@ -48,11 +62,9 @@
48 62
49 63 /**
50 64 * Get the File instance of the original file.
51 65 *
52 - * @since 1.9.8
53 - * @access public
54 - * @author Grégory Viguier
66 + * @since 1.9.8
55 67 *
56 68 * @return File|false
57 69 */
58 70 public function get_original_file();
@@ -59,11 +71,9 @@
59 71
60 72 /**
61 73 * Get the File instance of the full size file.
62 74 *
63 - * @since 1.9.8
64 - * @access public
65 - * @author Grégory Viguier
75 + * @since 1.9.8
66 76 *
67 77 * @return File|false
68 78 */
69 79 public function get_fullsize_file();
@@ -70,11 +80,9 @@
70 80
71 81 /**
72 82 * Tell if the current media is valid.
73 83 *
74 - * @since 1.9
75 - * @access public
76 - * @author Grégory Viguier
84 + * @since 1.9
77 85 *
78 86 * @return bool
79 87 */
80 88 public function is_valid();
@@ -81,69 +89,65 @@
81 89
82 90 /**
83 91 * Tell if the current user is allowed to operate Imagify in this context.
84 92 *
85 - * @since 1.9
86 - * @access public
87 - * @author Grégory Viguier
93 + * @since 1.9
88 94 *
89 - * @param string $describer Capacity describer. See \Imagify\Context\ContextInterface->get_capacity() for possible values. Can also be a "real" user capacity.
95 + * @param string $describer Capacity describer. See \Imagify\Context\ContextInterface->get_capacity() for possible values. Can also be a "real" user capacity.
96 + *
90 97 * @return bool
91 98 */
92 99 public function current_user_can( $describer );
93 100
94 -
95 - /** ----------------------------------------------------------------------------------------- */
96 - /** OPTIMIZATION ============================================================================ */
97 - /** ----------------------------------------------------------------------------------------- */
98 -
99 101 /**
100 102 * Optimize a media files by pushing tasks into the queue.
101 103 *
102 - * @since 1.9
103 - * @access public
104 - * @author Grégory Viguier
104 + * @since 1.9
105 + * @since 2.3.2 Added the $args parameter (e.g. 'bulk', 'priority').
105 106 *
106 - * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
107 - * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
107 + * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
108 + * @param array $args An array of optionnal arguments.
109 + *
110 + * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
108 111 */
109 - public function optimize( $optimization_level = null );
112 + public function optimize( $optimization_level = null, $args = [] );
110 113
111 114 /**
112 115 * Re-optimize a media files with a different level.
113 116 *
114 - * @since 1.9
115 - * @access public
116 - * @author Grégory Viguier
117 + * @since 1.9
118 + * @since 2.3.2 Added the $args parameter (e.g. 'bulk', 'priority').
117 119 *
118 - * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
119 - * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
120 + * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
121 + * @param array $args An array of optionnal arguments.
122 + *
123 + * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
120 124 */
121 - public function reoptimize( $optimization_level = null );
125 + public function reoptimize( $optimization_level = null, $args = [] );
122 126
123 127 /**
124 128 * Optimize several file sizes by pushing tasks into the queue.
125 129 *
126 - * @since 1.9
127 - * @access public
128 - * @author Grégory Viguier
130 + * @since 1.9
131 + * @since 2.3.2 Added the $args parameter (e.g. 'bulk', 'priority').
129 132 *
130 133 * @param array $sizes An array of media sizes (strings). Use "full" for the size of the main file.
131 134 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
132 - * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
135 + * @param array $args An array of optionnal arguments.
136 + *
137 + * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
133 138 */
134 - public function optimize_sizes( $sizes, $optimization_level = null );
139 + public function optimize_sizes( $sizes, $optimization_level = null, $args = [] );
135 140
136 141 /**
137 142 * Optimize one file with Imagify directly.
138 143 *
139 - * @since 1.9
140 - * @access public
141 - * @author Grégory Viguier
144 + * @since 1.9
142 145 *
143 - * @param string $size The media size.
144 - * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
145 - * @return array|WP_Error The optimization data. A \WP_Error instance on failure.
146 + * @param string $size The media size.
147 + * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
148 + *
149 + * @return array|WP_Error The optimization data. A \WP_Error instance on failure.
146 150 */
147 151 public function optimize_size( $size, $optimization_level = null );
148 152
149 153 /**
@@ -148,29 +152,20 @@
148 152
149 153 /**
150 154 * Restore the media files from the backup file.
151 155 *
152 - * @since 1.9
153 - * @access public
154 - * @author Grégory Viguier
156 + * @since 1.9
155 157 *
156 158 * @return bool|WP_Error True on success. A \WP_Error instance on failure.
157 159 */
158 160 public function restore();
159 161
160 -
161 - /** ----------------------------------------------------------------------------------------- */
162 - /** MISSING THUMBNAILS ====================================================================== */
163 - /** ----------------------------------------------------------------------------------------- */
164 -
165 162 /**
166 163 * Get the sizes for this media that have not get through optimization.
167 164 * No sizes are returned if the file is not optimized, has no backup, or is not an image.
168 165 * The 'full' size os never returned.
169 166 *
170 - * @since 1.9
171 - * @access public
172 - * @author Grégory Viguier
167 + * @since 1.9
173 168 *
174 169 * @return array|WP_Error {
175 170 * A WP_Error object on failure.
176 171 * An array of data for the thumbnail sizes on success.
@@ -187,44 +182,29 @@
187 182
188 183 /**
189 184 * Optimize missing thumbnail sizes.
190 185 *
191 - * @since 1.9
192 - * @access public
193 - * @author Grégory Viguier
186 + * @since 1.9
194 187 *
195 188 * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
196 189 */
197 190 public function optimize_missing_thumbnails();
198 191
199 -
200 - /** ----------------------------------------------------------------------------------------- */
201 - /** BACKUP FILE ============================================================================= */
202 - /** ----------------------------------------------------------------------------------------- */
203 -
204 192 /**
205 193 * Delete the backup file.
206 194 *
207 - * @since 1.9
208 - * @access public
209 - * @author Grégory Viguier
195 + * @since 1.9
210 196 */
211 197 public function delete_backup();
212 198
213 -
214 - /** ----------------------------------------------------------------------------------------- */
215 - /** RESIZE FILE ============================================================================= */
216 - /** ----------------------------------------------------------------------------------------- */
217 -
218 199 /**
219 200 * Maybe resize an image.
220 201 *
221 - * @since 1.9
222 - * @access protected
223 - * @author Grégory Viguier
202 + * @since 1.9
224 203 *
225 - * @param string $size The size name.
226 - * @param File $file A File instance.
204 + * @param string $size The size name.
205 + * @param File $file A File instance.
206 + *
227 207 * @return array|WP_Error A \WP_Error instance on failure, an array on success as follow: {
228 208 * @type bool $resized True when the image has been resized.
229 209 * @type bool $backuped True when the image has been backuped.
230 210 * @type int $file_size The file size in bytes.
@@ -231,72 +211,60 @@
231 211 * }
232 212 */
233 213 public function maybe_resize( $size, $file );
234 214
235 -
236 - /** ----------------------------------------------------------------------------------------- */
237 - /** WEBP ==================================================================================== */
238 - /** ----------------------------------------------------------------------------------------- */
239 -
240 215 /**
241 - * Generate WebP images if they are missing.
216 + * Generate next-gen images if they are missing.
242 217 *
243 - * @since 1.9
244 - * @access public
245 - * @author Grégory Viguier
218 + * @since 1.9
246 219 *
247 220 * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
248 221 */
249 - public function generate_webp_versions();
222 + public function generate_nextgen_versions();
250 223
251 224 /**
252 - * Delete the WebP images.
225 + * Delete the next gen format images.
253 226 * This doesn't delete the related optimization data.
254 227 *
255 - * @since 1.9
256 - * @since 1.9.6 Return WP_Error or true.
257 - * @access public
258 - * @author Grégory Viguier
228 + * @since 2.2
259 229 *
260 - * @param bool $keep_full Set to true to keep the full size.
261 - * @return bool|\WP_Error True on success. A \WP_Error object on failure.
230 + * @param bool $keep_full Set to true to keep the full size.
231 + *
232 + * @return bool|WP_Error True on success. A \WP_Error object on failure.
262 233 */
263 - public function delete_webp_files( $keep_full = false );
234 + public function delete_nextgen_files( $keep_full = false );
264 235
265 236 /**
266 - * Tell if a thumbnail size is an "Imagify WebP" size.
237 + * Tell if a thumbnail size is an "Imagify Next-Gen" size.
267 238 *
268 - * @since 1.9
269 - * @access public
270 - * @author Grégory Viguier
239 + * @since 2.2
271 240 *
272 - * @param string $size_name The size name.
273 - * @return string|bool The unsuffixed name of the size if WebP. False if not WebP.
241 + * @param string $size_name The size name.
242 + *
243 + * @return string|bool The unsuffixed name of the size if next-gen. False if not next-gen.
274 244 */
275 - public function is_size_webp( $size_name );
245 + public function is_size_next_gen( $size_name );
276 246
277 247 /**
278 - * Tell if the media has WebP versions.
248 + * Tell if the media has all next-gen versions.
279 249 *
280 - * @since 1.9
281 - * @access public
282 - * @author Grégory Viguier
250 + * @return bool
251 + */
252 + public function is_full_next_gen();
253 +
254 + /**
255 + * Tell if the media has a next-gen format.
283 256 *
257 + * @since 2.2
258 + *
284 259 * @return bool
285 260 */
286 - public function has_webp();
261 + public function has_next_gen();
287 262
288 -
289 - /** ----------------------------------------------------------------------------------------- */
290 - /** PROCESS STATUS ========================================================================== */
291 - /** ----------------------------------------------------------------------------------------- */
292 -
293 263 /**
294 264 * Tell if a process is running for this media.
295 265 *
296 - * @since 1.9
297 - * @access public
298 - * @author Grégory Viguier
266 + * @since 1.9
299 267 *
300 268 * @return bool
301 269 */
302 270 public function is_locked();
@@ -303,11 +271,9 @@
303 271
304 272 /**
305 273 * Set the running status to "running" for a period of time.
306 274 *
307 - * @since 1.9
308 - * @access public
309 - * @author Grégory Viguier
275 + * @since 1.9
310 276 */
311 277 public function lock();
312 278
313 279 /**
@@ -312,27 +278,19 @@
312 278
313 279 /**
314 280 * Delete the running status.
315 281 *
316 - * @since 1.9
317 - * @access public
318 - * @author Grégory Viguier
282 + * @since 1.9
319 283 */
320 284 public function unlock();
321 285
322 -
323 - /** ----------------------------------------------------------------------------------------- */
324 - /** DATA ==================================================================================== */
325 - /** ----------------------------------------------------------------------------------------- */
326 -
327 286 /**
328 287 * Tell if a size already has optimization data.
329 288 *
330 - * @since 1.9
331 - * @access public
332 - * @author Grégory Viguier
289 + * @since 1.9
333 290 *
334 - * @param string $size The size name.
291 + * @param string $size The size name.
292 + *
335 293 * @return bool
336 294 */
337 295 public function size_has_optimization_data( $size );
338 296
@@ -338,15 +296,14 @@
338 296
339 297 /**
340 298 * Update the optimization data for a size.
341 299 *
342 - * @since 1.9
343 - * @access public
344 - * @author Grégory Viguier
300 + * @since 1.9
345 301 *
346 - * @param object $response The API response.
347 - * @param string $size The size name.
348 - * @param int $level The optimization level (0=normal, 1=aggressive, 2=ultra).
302 + * @param object $response The API response.
303 + * @param string $size The size name.
304 + * @param int $level The optimization level (0=normal, 1=aggressive, 2=ultra).
305 + *
349 306 * @return array {
350 307 * The optimization data.
351 308 *
352 309 * @type string $size The size name.