From 621603e8400fe7caa89bec46cc619e694dcd24da Mon Sep 17 00:00:00 2001 From: Sergey Mitroshin Date: Wed, 1 Apr 2020 20:53:05 -0500 Subject: [PATCH] Autoloader: Skip single-file plugins (#15232) 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. --- .../autoloader/src/class-plugins-handler.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/autoloader/src/class-plugins-handler.php b/packages/autoloader/src/class-plugins-handler.php index 52c802528465e..2df354952717c 100644 --- a/packages/autoloader/src/class-plugins-handler.php +++ b/packages/autoloader/src/class-plugins-handler.php @@ -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() ) ) @@ -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