PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
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 / migration-meta.php

migration-meta.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.7, at classes/migration/migration-meta.php

77 lines 1.8 KB
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;
4
5 use DateTime;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 class Migration_Meta {
12 public const IMAGE_OPTIMIZER_MIGRATION_KEY = 'image_optimizer_migrations';
13 private const INITIAL_META_VALUE = [
14 'last_run' => null,
15 'last_wp_version_run' => null,
16 'migrations_passed' => [],
17 ];
18 private array $migration_meta;
19
20 public function get_last_run(): ?string {
21 return $this->migration_meta['last_run'];
22 }
23
24 public function set_last_run( DateTime $date ): Migration_Meta {
25 $this->migration_meta['last_run'] = $date;
26
27 return $this;
28 }
29
30 public function get_last_wp_version(): string {
31 return $this->migration_meta['last_wp_version_run'];
32 }
33
34 public function set_last_wp_version( ?string $version ): Migration_Meta {
35 if ( ! $version ) {
36 $this->migration_meta['last_wp_version_run'] = get_bloginfo( 'version' );
37
38 return $this;
39 }
40
41 $this->migration_meta['last_wp_version_run'] = $version;
42
43 return $this;
44 }
45
46 public function get_migrations_passed(): array {
47 return $this->migration_meta['migrations_passed'];
48 }
49
50 public function add_migration_passed( string $migration ): Migration_Meta {
51 $this->migration_meta['migrations_passed'][] = $migration;
52
53 return $this;
54 }
55
56 public function delete(): bool {
57 return delete_option( self::IMAGE_OPTIMIZER_MIGRATION_KEY );
58 }
59
60 public function save(): Migration_Meta {
61 update_option( self::IMAGE_OPTIMIZER_MIGRATION_KEY, $this->migration_meta, false );
62
63 $this->query_meta();
64
65 return $this;
66 }
67
68 private function query_meta(): void {
69 $meta = get_option( self::IMAGE_OPTIMIZER_MIGRATION_KEY, [] );
70 $this->migration_meta = $meta ? array_replace_recursive( self::INITIAL_META_VALUE, $meta ) : self::INITIAL_META_VALUE;
71 }
72
73 public function __construct() {
74 $this->query_meta();
75 }
76 }
77