Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
crstauf committed Dec 9, 2024
1 parent 4326df7 commit 3f36d93
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
17 changes: 14 additions & 3 deletions classes/ActionScheduler_AdminView.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,19 @@ public function add_help_tabs() {
return;
}

$as_version = ActionScheduler_Versions::instance()->latest_version();
$as_source = ActionScheduler_Versions::instance()->active_source();
$as_version = ActionScheduler_Versions::instance()->latest_version();
$as_source = ActionScheduler_Versions::instance()->active_source();
$as_source_path = ActionScheduler_Versions::instance()->active_source_path();
$as_source_markup = sprintf( '<code>%s</code>', esc_html( $as_source_path ) );

if ( ! empty( $as_source ) ) {
$as_source_markup = sprintf(
'%s: <abbr title="%s">%s</abbr>',
ucfirst( $as_source['type'] ),
esc_attr( $as_source_path ),
esc_html( $as_source['name'] )
);
}

$screen->add_help_tab(
array(
Expand All @@ -267,7 +278,7 @@ public function add_help_tabs() {
'<p>' .
esc_html__( 'Action Scheduler is currently being loaded from the following location. This can be useful when debugging, or if requested by the support team.', 'action-scheduler' ) .
'</p>' .
'<p><code>' . esc_html( $as_source ) . '</code></p>' .
'<p>' . $as_source_markup . '</p>' .
'<h3>' . esc_html__( 'WP CLI', 'action-scheduler' ) . '</h3>' .
'<p>' .
sprintf(
Expand Down
52 changes: 52 additions & 0 deletions classes/ActionScheduler_Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,58 @@ public static function initialize_latest_version() {
}

public function active_source() {
$file = __FILE__;
$dir = __DIR__;
$path = $this->active_source_path();
$themes = (array) search_theme_directories();

foreach ( $themes as $slug => $data ) {
$needle = trailingslashit( $data['theme_root'] ) . $slug . '/';

if ( 0 !== strpos( $file, $needle ) ) {
continue;
}

$theme = wp_get_theme( $slug );

if ( ! is_object( $theme ) || ! is_a( $theme, \WP_Theme::class ) ) {
continue;
}

return array(
'type' => 'theme',
'name' => $theme->Name,
);
}

$plugins = get_plugins();
$plugin_files = array_keys( $plugins );
$plugin_paths = array();

foreach ( $plugin_files as $plugin_file ) {
$plugin_path = trailingslashit( WP_PLUGIN_DIR ) . dirname( $plugin_file );
$plugin_file = trailingslashit( WP_PLUGIN_DIR ) . $plugin_file;

if ( 0 !== strpos( dirname( $dir ), $plugin_path ) ) {
continue;
}

$plugin_data = get_plugin_data( $plugin_file );

if ( ! is_array( $plugin_data ) || empty( $plugin_data['Name'] ) ) {
continue;
}

return array(
'type' => 'plugin',
'name' => $plugin_data['Name'],
);
}

return array();
}

public function active_source_path() {
return trailingslashit( dirname( __DIR__ ) );
}
}

0 comments on commit 3f36d93

Please sign in to comment.