diff --git a/classes/ActionScheduler_Versions.php b/classes/ActionScheduler_Versions.php index 4bde8839..6985d010 100644 --- a/classes/ActionScheduler_Versions.php +++ b/classes/ActionScheduler_Versions.php @@ -17,6 +17,7 @@ class ActionScheduler_Versions { * @var array */ private $versions = array(); + private $sources = array(); /** * Register version's callback. @@ -28,7 +29,12 @@ public function register( $version_string, $initialization_callback ) { if ( isset( $this->versions[ $version_string ] ) ) { return false; } + + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); + $source = $backtrace[0]['file']; + $this->versions[ $version_string ] = $initialization_callback; + $this->sources[ $source ] = $version_string; return true; } @@ -39,6 +45,10 @@ public function get_versions() { return $this->versions; } + public function get_sources() { + return $this->sources; + } + /** * Get latest version registered. */ diff --git a/classes/WP_CLI/System_Command.php b/classes/WP_CLI/System_Command.php index 5a585b5c..44b33ce6 100644 --- a/classes/WP_CLI/System_Command.php +++ b/classes/WP_CLI/System_Command.php @@ -132,6 +132,35 @@ public function version( array $args, array $assoc_args ) { echo $latest; } + /** + * Get all system sources. + * + * @param array $args Positional args. + * @param array $assoc_args Keyed args. + * @uses \ActionScheduler_Versions::get_sources() + * @uses \WP_CLI\Formatter::display_items() + * @uses $this->get_latest_version() + * @return void + */ + public function sources( array $args, array $assoc_args ) { + $instance = \ActionScheduler_Versions::instance(); + $sources = $instance->get_sources(); + + $rows = array(); + + foreach ( $sources as $source => $version ) { + $rows[ $source ] = array( + 'source' => str_replace( ABSPATH, '', $source ), + 'version' => $version, + ); + } + + ksort( $rows ); + + $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'source', 'version' ) ); + $formatter->display_items( $rows ); + } + /** * Get current data store. *