Skip to content

Commit e139137

Browse files
crstaufbarryhughes
authored andcommitted
search plugins first, themes second
1 parent 3b5c39f commit e139137

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

classes/ActionScheduler_Versions.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,49 +115,49 @@ public static function initialize_latest_version() {
115115
* @return string
116116
*/
117117
public function active_source() {
118-
$file = __FILE__;
119-
$dir = __DIR__;
120-
$themes = (array) search_theme_directories();
118+
$file = __FILE__;
119+
$dir = __DIR__;
120+
$plugins = get_plugins();
121+
$plugin_files = array_keys( $plugins );
121122

122-
foreach ( $themes as $slug => $data ) {
123-
$needle = trailingslashit( $data['theme_root'] ) . $slug . '/';
123+
foreach ( $plugin_files as $plugin_file ) {
124+
$plugin_path = trailingslashit( WP_PLUGIN_DIR ) . dirname( $plugin_file );
125+
$plugin_file = trailingslashit( WP_PLUGIN_DIR ) . $plugin_file;
124126

125-
if ( 0 !== strpos( $file, $needle ) ) {
127+
if ( 0 !== strpos( dirname( $dir ), $plugin_path ) ) {
126128
continue;
127129
}
128130

129-
$theme = wp_get_theme( $slug );
131+
$plugin_data = get_plugin_data( $plugin_file );
130132

131-
if ( ! is_object( $theme ) || ! is_a( $theme, \WP_Theme::class ) ) {
133+
if ( ! is_array( $plugin_data ) || empty( $plugin_data['Name'] ) ) {
132134
continue;
133135
}
134136

135137
return array(
136-
'type' => 'theme',
137-
'name' => $theme->Name,
138+
'type' => 'plugin',
139+
'name' => $plugin_data['Name'],
138140
);
139141
}
140142

141-
$plugins = get_plugins();
142-
$plugin_files = array_keys( $plugins );
143+
$themes = (array) search_theme_directories();
143144

144-
foreach ( $plugin_files as $plugin_file ) {
145-
$plugin_path = trailingslashit( WP_PLUGIN_DIR ) . dirname( $plugin_file );
146-
$plugin_file = trailingslashit( WP_PLUGIN_DIR ) . $plugin_file;
145+
foreach ( $themes as $slug => $data ) {
146+
$needle = trailingslashit( $data['theme_root'] ) . $slug . '/';
147147

148-
if ( 0 !== strpos( dirname( $dir ), $plugin_path ) ) {
148+
if ( 0 !== strpos( $file, $needle ) ) {
149149
continue;
150150
}
151151

152-
$plugin_data = get_plugin_data( $plugin_file );
152+
$theme = wp_get_theme( $slug );
153153

154-
if ( ! is_array( $plugin_data ) || empty( $plugin_data['Name'] ) ) {
154+
if ( ! is_object( $theme ) || ! is_a( $theme, \WP_Theme::class ) ) {
155155
continue;
156156
}
157157

158158
return array(
159-
'type' => 'plugin',
160-
'name' => $plugin_data['Name'],
159+
'type' => 'theme',
160+
'name' => $theme->Name,
161161
);
162162
}
163163

0 commit comments

Comments
 (0)