| @@ -1,9 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Imagify\Optimization\Data; |
| 3 | 3 | |
| 4 | -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); | |
| 5 | - | |
| 6 | 4 | /** |
| 7 | 5 | * Optimization data class for the medias in the WP library. |
| 8 | 6 | * This class constructor accepts: |
| 9 | 7 | * - A post ID (int). |
| @@ -88,22 +86,41 @@ | ||
| 88 | 86 | if ( ! isset( $old_data['stats'] ) || ! is_array( $old_data['stats'] ) ) { |
| 89 | 87 | $old_data['stats'] = []; |
| 90 | 88 | } |
| 91 | 89 | |
| 92 | - $old_data['stats'] = array_merge( [ | |
| 93 | - 'original_size' => 0, | |
| 94 | - 'optimized_size' => 0, | |
| 95 | - 'percent' => 0, | |
| 96 | - ], $old_data['stats'] ); | |
| 90 | + $old_data['stats'] = array_merge( | |
| 91 | + [ | |
| 92 | + 'original_size' => 0, | |
| 93 | + 'optimized_size' => 0, | |
| 94 | + 'percent' => 0, | |
| 95 | + 'message' => '', | |
| 96 | + ], | |
| 97 | + $old_data['stats'] | |
| 98 | + ); | |
| 97 | 99 | |
| 100 | + if ( key_exists( 'message', $data ) ) { | |
| 101 | + $old_data['message'] = $data['message']; | |
| 102 | + } | |
| 103 | + | |
| 98 | 104 | if ( ! $data['success'] ) { |
| 99 | 105 | /** |
| 100 | 106 | * Error. |
| 101 | 107 | */ |
| 102 | - $old_data['sizes'][ $size ] = [ | |
| 108 | + $size_data = [ | |
| 103 | 109 | 'success' => false, |
| 104 | 110 | 'error' => $data['error'], |
| 105 | 111 | ]; |
| 112 | + | |
| 113 | + if ( ! empty( $data['permanent_error'] ) ) { | |
| 114 | + /** | |
| 115 | + * `permanent_error` is written as the FIRST key on purpose: the bulk queries match the | |
| 116 | + * serialized meta value with a LIKE on the `<size>";a:3:{s:15:"permanent_error";b:1;` | |
| 117 | + * prefix, which only stays deterministic if the key order does. | |
| 118 | + */ | |
| 119 | + $size_data = array_merge( [ 'permanent_error' => true ], $size_data ); | |
| 120 | + } | |
| 121 | + | |
| 122 | + $old_data['sizes'][ $size ] = $size_data; | |
| 106 | 123 | } else { |
| 107 | 124 | /** |
| 108 | 125 | * Success. |
| 109 | 126 | */ |