PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / classes / migration / handlers / fix-optimized-size-keys.php

fix-optimized-size-keys.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.4, at classes/migration/handlers/fix-optimized-size-keys.php

42 lines 823 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Classes\Migration\Handlers;
4
5 use ImageOptimization\Classes\Image\{
6 Image_Meta,
7 Image_Query_Builder,
8 };
9
10 use ImageOptimization\Classes\Migration\Migration;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 class Fix_Optimized_Size_Keys extends Migration {
17 public static function get_name(): string {
18 return 'fix_optimized_size_keys';
19 }
20
21 public static function run(): bool {
22 $query = ( new Image_Query_Builder() )
23 ->return_optimized_images()
24 ->execute();
25
26 if ( ! $query->post_count ) {
27 return true;
28 }
29
30 foreach ( $query->posts as $attachment_id ) {
31 $meta = new Image_Meta( $attachment_id );
32 $size_keys = array_unique( $meta->get_optimized_sizes() );
33
34 $meta
35 ->set_optimized_size( $size_keys )
36 ->save();
37 }
38
39 return true;
40 }
41 }
42