Skip to content

Instantly share code, notes, and snippets.

@trvswgnr
Created April 26, 2020 07:56
Show Gist options
  • Save trvswgnr/64bc9237f420a4d56097447b11396625 to your computer and use it in GitHub Desktop.
Save trvswgnr/64bc9237f420a4d56097447b11396625 to your computer and use it in GitHub Desktop.
Automatically load plugins in folders inside the mu-plugins folder
<?php
/**
* Automatically loads plugins in folders
*
* @package mu-plugin-autoloader
*/
$dirs = array_filter( glob( WPMU_PLUGIN_DIR . '/*' ), 'is_dir' );
foreach ( $dirs as $dirpath ) {
$regex = '/([^\/]+$)/';
preg_match( $regex, $dirpath, $matches );
$dirname = $matches[0];
require_once WPMU_PLUGIN_DIR . "/$dirname/$dirname.php";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment