My autoloader class is responsible for loading must-use plugins that do not sit in the root of the mu-plugins
folder. To locate them, I need to use the get_plugins()
function. According to Codex, the function accepts one parameter:
$plugin_folder (string) (optional): Relative path to single plugin folder.
My file hierarchy looks like this:
|-- /mu-plugins
| |-- autoload.php // only includes wpmu/autoload.php
| |-- /wpmu
| | |-- autoload.php // uses **get_plugins()** and autoloads other MU plugins
| |-- /mu-plugin-to-autoload-A
| | |-- plugin-file-to-autoload.php // this plugin file should be autoloaded
| |-- /mu-plugin-to-autoload-B
| | |-- plugin-file-to-autoload.php // this plugin file should be autoloaded
I thought I should go at it this way:
// array to store plugins
$plugins = [];
// get mu-plugin folders
$plugin_dirs = glob(WPMU_PLUGIN_DIR . '/*' , GLOB_ONLYDIR);
// loop through mu-plugin folders
foreach ($plugin_dirs as $plugin_dir) {
$plugins[] = get_plugins($plugin_dir);
}
However get_plugins() function returns an empty array.
I want to achieve similar functionality as Sébastien Lavoie did in his Gist on GitHub. Its script should sit on the root of WPMU folder, as it uses get_plugins('/../mu-plugins')
, which I do not understand at all (does it move back and forth to wpmu plugins folder?).
$plugins = array();
foreach (get_plugins('/../mu-plugins') as $plugin_file => $data) {
if (dirname($plugin_file) != '.') { // skip files directly at root
$plugins[] = $plugin_file;
}
}
Nevertheless, it works (as I've tested it).
I hope all makes sense. :)
get_plugins()
function. The link to the final script will be only part of the answer, intended for anyone interested in full problem (autoloading MU plugins).