WP_CLI
1 year ago
abstracts
1 year ago
actions
1 year ago
data-stores
1 year ago
migration
1 year ago
schedules
1 year ago
schema
1 year ago
ActionScheduler_ActionClaim.php
1 year ago
ActionScheduler_ActionFactory.php
1 year ago
ActionScheduler_AdminView.php
1 year ago
ActionScheduler_AsyncRequest_QueueRunner.php
1 year ago
ActionScheduler_Compatibility.php
1 year ago
ActionScheduler_DataController.php
1 year ago
ActionScheduler_DateTime.php
1 year ago
ActionScheduler_Exception.php
4 years ago
ActionScheduler_FatalErrorMonitor.php
1 year ago
ActionScheduler_InvalidActionException.php
1 year ago
ActionScheduler_ListTable.php
1 year ago
ActionScheduler_LogEntry.php
1 year ago
ActionScheduler_NullLogEntry.php
1 year ago
ActionScheduler_OptionLock.php
2 years ago
ActionScheduler_QueueCleaner.php
1 year ago
ActionScheduler_QueueRunner.php
1 year ago
ActionScheduler_SystemInformation.php
1 year ago
ActionScheduler_Versions.php
1 year ago
ActionScheduler_WPCommentCleaner.php
1 year ago
ActionScheduler_wcSystemStatus.php
4 years ago
index.php
3 years ago
ActionScheduler_Versions.php
58 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | class ActionScheduler_Versions { |
| 4 | private static $instance = null; |
| 5 | private $versions = array(); |
| 6 | private $sources = array(); |
| 7 | public function register( $version_string, $initialization_callback ) { |
| 8 | if ( isset( $this->versions[ $version_string ] ) ) { |
| 9 | return false; |
| 10 | } |
| 11 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace |
| 12 | $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); |
| 13 | $source = $backtrace[0]['file']; |
| 14 | $this->versions[ $version_string ] = $initialization_callback; |
| 15 | $this->sources[ $source ] = $version_string; |
| 16 | return true; |
| 17 | } |
| 18 | public function get_versions() { |
| 19 | return $this->versions; |
| 20 | } |
| 21 | public function get_sources() { |
| 22 | return $this->sources; |
| 23 | } |
| 24 | public function latest_version() { |
| 25 | $keys = array_keys( $this->versions ); |
| 26 | if ( empty( $keys ) ) { |
| 27 | return false; |
| 28 | } |
| 29 | uasort( $keys, 'version_compare' ); |
| 30 | return end( $keys ); |
| 31 | } |
| 32 | public function latest_version_callback() { |
| 33 | $latest = $this->latest_version(); |
| 34 | if ( empty( $latest ) || ! isset( $this->versions[ $latest ] ) ) { |
| 35 | return '__return_null'; |
| 36 | } |
| 37 | return $this->versions[ $latest ]; |
| 38 | } |
| 39 | public static function instance() { |
| 40 | if ( empty( self::$instance ) ) { |
| 41 | self::$instance = new self(); |
| 42 | } |
| 43 | return self::$instance; |
| 44 | } |
| 45 | public static function initialize_latest_version() { |
| 46 | $self = self::instance(); |
| 47 | call_user_func( $self->latest_version_callback() ); |
| 48 | } |
| 49 | public function active_source(): array { |
| 50 | _deprecated_function( __METHOD__, '3.9.2', 'ActionScheduler_SystemInformation::active_source()' ); |
| 51 | return ActionScheduler_SystemInformation::active_source(); |
| 52 | } |
| 53 | public function active_source_path(): string { |
| 54 | _deprecated_function( __METHOD__, '3.9.2', 'ActionScheduler_SystemInformation::active_source_path()' ); |
| 55 | return ActionScheduler_SystemInformation::active_source_path(); |
| 56 | } |
| 57 | } |
| 58 |