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/Data/CustomFolders.php +27 -6 1.10 → trunk View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2 namespace Imagify\Optimization\Data;
3 3
4 -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
4 +use Imagify\Traits\MediaRowTrait;
5 5
6 6 /**
7 7 * Optimization data class for the custom folders.
8 8 * This class constructor accepts:
@@ -15,9 +15,9 @@
15 15 * @see Imagify\Media\CustomFolders
16 16 * @author Grégory Viguier
17 17 */
18 18 class CustomFolders extends AbstractData {
19 - use \Imagify\Traits\MediaRowTrait;
19 + use MediaRowTrait;
20 20
21 21 /**
22 22 * The attachment SQL DB class.
23 23 *
@@ -43,13 +43,19 @@
43 43 if ( ! $this->is_valid() ) {
44 44 return;
45 45 }
46 46
47 + $media = $this->get_media();
48 +
49 + if ( ! $media ) {
50 + return;
51 + }
52 +
47 53 // This is required by MediaRowTrait.
48 - $this->id = $this->get_media()->get_id();
54 + $this->id = $media->get_id();
49 55
50 56 // In this context, the media data and the optimization data are stored in the same DB table, so, no need to request twice the DB.
51 - $this->row = $this->get_media()->get_row();
57 + $this->row = $media->get_row(); // @phpstan-ignore-line
52 58 }
53 59
54 60 /**
55 61 * Get the whole media optimization data.
@@ -158,8 +164,12 @@
158 164 if ( $file_path ) {
159 165 $old_data['hash'] = md5_file( $file_path );
160 166 }
161 167
168 + if ( key_exists( 'message', $data ) ) {
169 + $old_data['message'] = $data['message'];
170 + }
171 +
162 172 if ( ! $data['success'] ) {
163 173 /**
164 174 * Error.
165 175 */
@@ -176,9 +186,9 @@
176 186 } else {
177 187 /**
178 188 * WebP version or any other size.
179 189 */
180 - $old_data['data'] = ! empty( $old_data['data'] ) && is_array( $old_data['data'] ) ? $old_data['data'] : [];
190 + $old_data['data'] = ! empty( $old_data['data'] ) && is_array( $old_data['data'] ) ? $old_data['data'] : [];
181 191 $old_data['data']['sizes'] = ! empty( $old_data['data']['sizes'] ) && is_array( $old_data['data']['sizes'] ) ? $old_data['data']['sizes'] : [];
182 192
183 193 if ( ! $data['success'] ) {
184 194 /**
@@ -183,12 +193,23 @@
183 193 if ( ! $data['success'] ) {
184 194 /**
185 195 * Error.
186 196 */
187 - $old_data['data']['sizes'][ $size ] = [
197 + $size_data = [
188 198 'success' => false,
189 199 'error' => $data['error'],
190 200 ];
201 +
202 + if ( ! empty( $data['permanent_error'] ) ) {
203 + /**
204 + * `permanent_error` is written as the FIRST key on purpose: the bulk queries match the
205 + * serialized data with a LIKE on the `<size>";a:3:{s:15:"permanent_error";b:1;` prefix,
206 + * which only stays deterministic if the key order does.
207 + */
208 + $size_data = array_merge( [ 'permanent_error' => true ], $size_data );
209 + }
210 +
211 + $old_data['data']['sizes'][ $size ] = $size_data;
191 212 } else {
192 213 /**
193 214 * Success.
194 215 */