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
imagify / classes / Optimization / NextGenMarker.php

NextGenMarker.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at classes/Optimization/NextGenMarker.php

46 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare(strict_types=1);
3
4 namespace Imagify\Optimization;
5
6 /**
7 * Builds the fragile serialized-data needles used to detect, via a `LIKE`/`NOT LIKE` on the
8 * `_imagify_data` postmeta, whether a media has a successful next-gen size or was permanently
9 * refused by the API.
10 *
11 * These strings depend on the exact key order Imagify writes when serializing a size's
12 * optimization data (see `Imagify\Optimization\Data\WP::update_size_optimization_data()`), so any
13 * consumer must go through this class rather than retyping the literal.
14 *
15 * Two other copies of the same literals currently exist in `classes/Bulk/WP.php` (around lines
16 * 320 and 325, for the `permanent_error` and `success` markers respectively) and in
17 * `classes/Optimization/Process/AbstractProcess::has_avif()`. They predate this helper and were
18 * left untouched to avoid destabilizing branches with in-flight changes; whoever next touches
19 * those call sites should consider adopting this class instead.
20 */
21 class NextGenMarker {
22 /**
23 * Builds the needle matching a size that was successfully converted to the given next-gen
24 * format (e.g. `@imagify-webp";a:4:{s:7:"success";b:1;`).
25 *
26 * @param string $suffix The format suffix, e.g. `ProcessInterface::WEBP_SUFFIX` or `::AVIF_SUFFIX`.
27 *
28 * @return string
29 */
30 public static function success( string $suffix ): string {
31 return $suffix . '";a:4:{s:7:"success";b:1;';
32 }
33
34 /**
35 * Builds the needle matching a size the API permanently refused to convert (as opposed to a
36 * transient failure, which is retried and does not carry the `permanent_error` key).
37 *
38 * @param string $suffix The format suffix, e.g. `ProcessInterface::WEBP_SUFFIX` or `::AVIF_SUFFIX`.
39 *
40 * @return string
41 */
42 public static function permanent_error( string $suffix ): string {
43 return $suffix . '";a:3:{s:15:"permanent_error";b:1;';
44 }
45 }
46