WP_CLI
2 years ago
abstracts
5 months ago
actions
2 years ago
data-stores
2 years ago
migration
2 years ago
schedules
2 years ago
schema
2 years ago
ActionScheduler_ActionClaim.php
2 years ago
ActionScheduler_ActionFactory.php
2 years ago
ActionScheduler_AdminView.php
2 years ago
ActionScheduler_AsyncRequest_QueueRunner.php
2 years ago
ActionScheduler_Compatibility.php
2 years ago
ActionScheduler_DataController.php
2 years ago
ActionScheduler_DateTime.php
2 years ago
ActionScheduler_Exception.php
2 years ago
ActionScheduler_FatalErrorMonitor.php
2 years ago
ActionScheduler_InvalidActionException.php
2 years ago
ActionScheduler_ListTable.php
2 years ago
ActionScheduler_LogEntry.php
2 years ago
ActionScheduler_NullLogEntry.php
2 years ago
ActionScheduler_OptionLock.php
2 years ago
ActionScheduler_QueueCleaner.php
2 years ago
ActionScheduler_QueueRunner.php
2 years ago
ActionScheduler_Versions.php
2 years ago
ActionScheduler_WPCommentCleaner.php
2 years ago
ActionScheduler_wcSystemStatus.php
2 years ago
ActionScheduler_Versions.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class ActionScheduler_Versions |
| 5 | */ |
| 6 | class ActionScheduler_Versions { |
| 7 | /** |
| 8 | * @var ActionScheduler_Versions |
| 9 | */ |
| 10 | private static $instance = null; |
| 11 | |
| 12 | private $versions = array(); |
| 13 | |
| 14 | public function register( $version_string, $initialization_callback ) { |
| 15 | if ( isset( $this->versions[ $version_string ] ) ) { |
| 16 | return false; |
| 17 | } |
| 18 | $this->versions[ $version_string ] = $initialization_callback; |
| 19 | return true; |
| 20 | } |
| 21 | |
| 22 | public function get_versions() { |
| 23 | return $this->versions; |
| 24 | } |
| 25 | |
| 26 | public function latest_version() { |
| 27 | $keys = array_keys( $this->versions ); |
| 28 | if ( empty( $keys ) ) { |
| 29 | return false; |
| 30 | } |
| 31 | uasort( $keys, 'version_compare' ); |
| 32 | return end( $keys ); |
| 33 | } |
| 34 | |
| 35 | public function latest_version_callback() { |
| 36 | $latest = $this->latest_version(); |
| 37 | if ( empty( $latest ) || ! isset( $this->versions[ $latest ] ) ) { |
| 38 | return '__return_null'; |
| 39 | } |
| 40 | return $this->versions[ $latest ]; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @return ActionScheduler_Versions |
| 45 | * @codeCoverageIgnore |
| 46 | */ |
| 47 | public static function instance() { |
| 48 | if ( empty( self::$instance ) ) { |
| 49 | self::$instance = new self(); |
| 50 | } |
| 51 | return self::$instance; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @codeCoverageIgnore |
| 56 | */ |
| 57 | public static function initialize_latest_version() { |
| 58 | $self = self::instance(); |
| 59 | call_user_func( $self->latest_version_callback() ); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 |