Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple autoloader for WordPress Must-Use plugins. The loader assumes plugins use the format `{plugin-name}\{plugin-name}`.php for their core file. If not, they're skipped.
<?php
/**
* MU-Plugin Autoloader
*
* @author Eric Mann <eric@eamann.com>
* @license MIT
* @copyright 2015 Eric Mann
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$paths = scandir( dirname( __FILE__ ) );
$paths = array_diff( $paths, array( '..', '.' ) );
foreach( $paths as $maybe_plugin ) {
if ( strpos( $maybe_plugin, '.php' ) != 0 ) {
continue;
}
// Attempt to get the loader file.
$core_file = WPMU_PLUGIN_DIR . "/{$maybe_plugin}/{$maybe_plugin}.php";
if ( file_exists( $core_file ) ) {
require_once $core_file;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.