Created
May 1, 2019 18:07
-
-
Save chrisvanpatten/9840d1b854fd9e2dc4d7d445ff2500a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is for loading all mu-plugins within subfolders | |
* where the PHP file name is exactly like the directory name + .php. | |
* | |
* Example: /mu-tools/mu-tools.php | |
*/ | |
$dirs = glob( dirname( __FILE__ ) . '/*' , GLOB_ONLYDIR ); | |
// Get an array of plugin directories. | |
$plugins = array_map( function ( string $dir ) : ?array { | |
if ( ! file_exists( $dir . DIRECTORY_SEPARATOR . basename( $dir ) . ".php" ) ) { | |
return null; | |
} | |
return [ | |
basename( $dir ) => $dir . DIRECTORY_SEPARATOR . basename( $dir ) . '.php', | |
]; | |
}, $dirs ); | |
// Remove any invalid plugins. | |
$plugins = array_filter( $plugins, 'is_array' ); | |
// Load the plugins. | |
foreach ( $plugins as $plugin => $path ) { | |
require( $path ); | |
} | |
// Build UI to view the autoloaded must-use plugins. | |
add_action( 'admin_init', function () use ( $plugins ) { | |
$rows = []; | |
foreach ( $plugins as $plugin => $path ) { | |
$data = get_plugin_data( $path ); | |
$name = $data['Plugin Name'] ?? $plugin; | |
$desc = $data['Description'] ?? ' '; | |
$id = sanitize_title($name); | |
$rows[] = <<<HTML | |
<tr id="$id" class="active"> | |
<th scope="row" class="check-column"></th> | |
<td class="plugin-title"><strong style="padding-left: 10px;">+ $name</strong></td> | |
<td class="column-description desc"> | |
<div class="plugin-description"><p>$desc</p></div> | |
</td> | |
</tr> | |
HTML; | |
} | |
// Inject the HTML | |
add_action('after_plugin_row_mu-autoloader.php', function () use ( $rows ) { | |
implode( $rows ); | |
} ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment