Skip to content

Instantly share code, notes, and snippets.

@ericmann
Created April 24, 2015 23:23
Show Gist options
  • Save ericmann/608018a71cb04581b259 to your computer and use it in GitHub Desktop.
Save ericmann/608018a71cb04581b259 to your computer and use it in GitHub Desktop.
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 <[email protected]>
* @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