WP_CLI
11 months ago
abstracts
11 months ago
actions
1 year ago
data-stores
11 months ago
migration
1 year ago
schedules
1 year ago
schema
11 months 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
11 months ago
ActionScheduler_DateTime.php
1 year ago
ActionScheduler_Exception.php
3 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
1 year ago
ActionScheduler_QueueCleaner.php
1 year ago
ActionScheduler_QueueRunner.php
1 year ago
ActionScheduler_RecurringActionScheduler.php
11 months ago
ActionScheduler_SystemInformation.php
1 year ago
ActionScheduler_Versions.php
1 year ago
ActionScheduler_WPCommentCleaner.php
1 year ago
ActionScheduler_wcSystemStatus.php
11 months ago
ActionScheduler_SystemInformation.php
94 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Provides information about active and registered instances of Action Scheduler. |
| 5 | */ |
| 6 | class ActionScheduler_SystemInformation { |
| 7 | /** |
| 8 | * Returns information about the plugin or theme which contains the current active version |
| 9 | * of Action Scheduler. |
| 10 | * |
| 11 | * If this cannot be determined, or if Action Scheduler is being loaded via some other |
| 12 | * method, then it will return an empty array. Otherwise, if populated, the array will |
| 13 | * look like the following: |
| 14 | * |
| 15 | * [ |
| 16 | * 'type' => 'plugin', # or 'theme' |
| 17 | * 'name' => 'Name', |
| 18 | * ] |
| 19 | * |
| 20 | * @return array |
| 21 | */ |
| 22 | public static function active_source(): array { |
| 23 | $plugins = get_plugins(); |
| 24 | $plugin_files = array_keys( $plugins ); |
| 25 | |
| 26 | foreach ( $plugin_files as $plugin_file ) { |
| 27 | $plugin_path = trailingslashit( WP_PLUGIN_DIR ) . dirname( $plugin_file ); |
| 28 | $plugin_file = trailingslashit( WP_PLUGIN_DIR ) . $plugin_file; |
| 29 | |
| 30 | if ( 0 !== strpos( dirname( __DIR__ ), $plugin_path ) ) { |
| 31 | continue; |
| 32 | } |
| 33 | |
| 34 | $plugin_data = get_plugin_data( $plugin_file ); |
| 35 | |
| 36 | if ( ! is_array( $plugin_data ) || empty( $plugin_data['Name'] ) ) { |
| 37 | continue; |
| 38 | } |
| 39 | |
| 40 | return array( |
| 41 | 'type' => 'plugin', |
| 42 | 'name' => $plugin_data['Name'], |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | $themes = (array) search_theme_directories(); |
| 47 | |
| 48 | foreach ( $themes as $slug => $data ) { |
| 49 | $needle = trailingslashit( $data['theme_root'] ) . $slug . '/'; |
| 50 | |
| 51 | if ( 0 !== strpos( __FILE__, $needle ) ) { |
| 52 | continue; |
| 53 | } |
| 54 | |
| 55 | $theme = wp_get_theme( $slug ); |
| 56 | |
| 57 | if ( ! is_object( $theme ) || ! is_a( $theme, \WP_Theme::class ) ) { |
| 58 | continue; |
| 59 | } |
| 60 | |
| 61 | return array( |
| 62 | 'type' => 'theme', |
| 63 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
| 64 | 'name' => $theme->Name, |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | return array(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the directory path for the currently active installation of Action Scheduler. |
| 73 | * |
| 74 | * @return string |
| 75 | */ |
| 76 | public static function active_source_path(): string { |
| 77 | return trailingslashit( dirname( __DIR__ ) ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Get registered sources. |
| 82 | * |
| 83 | * It is not always possible to obtain this information. For instance, if earlier versions (<=3.9.0) of |
| 84 | * Action Scheduler register themselves first, then the necessary data about registered sources will |
| 85 | * not be available. |
| 86 | * |
| 87 | * @return array<string, string> |
| 88 | */ |
| 89 | public static function get_sources() { |
| 90 | $versions = ActionScheduler_Versions::instance(); |
| 91 | return method_exists( $versions, 'get_sources' ) ? $versions->get_sources() : array(); |
| 92 | } |
| 93 | } |
| 94 |