Skip to content

Commit

Permalink
Autoloader: Skip single-file plugins (#15232)
Browse files Browse the repository at this point in the history
Some plugins don't have a dedicated directory and only consist of a single file (e.g. 'Hello Dolly').
This means they also don't use Composer, so we can skip them entirely.
  • Loading branch information
sergeymitr authored and kbrown9 committed May 14, 2020
1 parent c71f298 commit 621603e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/autoloader/src/class-plugins-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ class Plugins_Handler {
* Returns an array containing all active plugins and all known activating
* plugins.
*
* @param bool $skip_single_file_plugins If true, plugins with no dedicated directories will be skipped.
*
* @return Array An array of plugin names as strings.
*/
public function get_all_active_plugins() {
public function get_all_active_plugins( $skip_single_file_plugins = true ) {
$active_plugins = array_merge(
is_multisite()
? array_keys( get_site_option( 'active_sitewide_plugins', array() ) )
Expand All @@ -22,9 +24,24 @@ public function get_all_active_plugins() {

$plugins = array_unique( array_merge( $active_plugins, $this->get_all_activating_plugins() ) );

if ( $skip_single_file_plugins ) {
$plugins = array_filter( $plugins, array( $this, 'is_directory_plugin' ) );
}

return $plugins;
}

/**
* Ensure the plugin has its own directory and not a single-file plugin.
*
* @param string $plugin Plugin name, may be prefixed with "/".
*
* @return bool
*/
public function is_directory_plugin( $plugin ) {
return false !== strpos( $plugin, '/', 1 );
}

/**
* Creates an array containing the paths to the classmap and filemap for the given plugin.
* The classmap and filemap filenames are the names of the files generated by Jetpack
Expand Down

0 comments on commit 621603e

Please sign in to comment.