PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.6
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.6
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 / vendor / woocommerce / action-scheduler / classes / ActionScheduler_Versions.php

ActionScheduler_Versions.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.6, at vendor/woocommerce/action-scheduler/classes/ActionScheduler_Versions.php

90 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_Versions
5 */
6 class ActionScheduler_Versions {
7 /**
8 * ActionScheduler_Versions instance.
9 *
10 * @var ActionScheduler_Versions
11 */
12 private static $instance = null;
13
14 /**
15 * Versions.
16 *
17 * @var array<string, callable>
18 */
19 private $versions = array();
20
21 /**
22 * Register version's callback.
23 *
24 * @param string $version_string Action Scheduler version.
25 * @param callable $initialization_callback Callback to initialize the version.
26 */
27 public function register( $version_string, $initialization_callback ) {
28 if ( isset( $this->versions[ $version_string ] ) ) {
29 return false;
30 }
31 $this->versions[ $version_string ] = $initialization_callback;
32 return true;
33 }
34
35 /**
36 * Get all versions.
37 */
38 public function get_versions() {
39 return $this->versions;
40 }
41
42 /**
43 * Get latest version registered.
44 */
45 public function latest_version() {
46 $keys = array_keys( $this->versions );
47 if ( empty( $keys ) ) {
48 return false;
49 }
50 uasort( $keys, 'version_compare' );
51 return end( $keys );
52 }
53
54 /**
55 * Get callback for latest registered version.
56 */
57 public function latest_version_callback() {
58 $latest = $this->latest_version();
59
60 if ( empty( $latest ) || ! isset( $this->versions[ $latest ] ) ) {
61 return '__return_null';
62 }
63
64 return $this->versions[ $latest ];
65 }
66
67 /**
68 * Get instance.
69 *
70 * @return ActionScheduler_Versions
71 * @codeCoverageIgnore
72 */
73 public static function instance() {
74 if ( empty( self::$instance ) ) {
75 self::$instance = new self();
76 }
77 return self::$instance;
78 }
79
80 /**
81 * Initialize.
82 *
83 * @codeCoverageIgnore
84 */
85 public static function initialize_latest_version() {
86 $self = self::instance();
87 call_user_func( $self->latest_version_callback() );
88 }
89 }
90