The get_mu_plugins() WordPress PHP function checks the mu-plugins directory and retrieves all mu-plugin files with any plugin data.
Usage
$mu_plugins = get_mu_plugins();
Parameters
- None
More information
See WordPress Developer Resources: get_mu_plugins()
Examples
Display a list of active mu-plugins
This example retrieves the list of active mu-plugins and displays their names and versions.
// Retrieve the mu-plugins $mu_plugins = get_mu_plugins(); // Loop through the mu-plugins and display their names and versions foreach ($mu_plugins as $plugin) { echo 'Plugin Name: ' . $plugin['Name'] . ', Version: ' . $plugin['Version'] . '<br>'; }
Check if a specific mu-plugin is active
This example checks if a specific mu-plugin named “Custom MU-Plugin” is active.
// Retrieve the mu-plugins $mu_plugins = get_mu_plugins(); // Check if the specific mu-plugin is active $plugin_name = 'Custom MU-Plugin'; $is_plugin_active = array_key_exists($plugin_name, $mu_plugins); // Display the result echo $is_plugin_active ? "The plugin is active." : "The plugin is not active.";
Get the total number of active mu-plugins
This example retrieves the total number of active mu-plugins.
// Retrieve the mu-plugins $mu_plugins = get_mu_plugins(); // Get the total number of active mu-plugins $total_plugins = count($mu_plugins); // Display the result echo 'Total active mu-plugins: ' . $total_plugins;
Retrieve mu-plugin data by a specific key
This example retrieves the mu-plugin data by a specific key, such as “Version” or “Author”.
// Retrieve the mu-plugins $mu_plugins = get_mu_plugins(); // Get mu-plugin data by a specific key $key = 'Version'; $data = array_map(function($plugin) use ($key) { return $plugin[$key]; }, $mu_plugins); // Display the result print_r($data);
Filter mu-plugins by a specific author
This example filters the mu-plugins by a specific author and displays their names.
// Retrieve the mu-plugins $mu_plugins = get_mu_plugins(); // Filter mu-plugins by a specific author $author = 'John Doe'; $filtered_plugins = array_filter($mu_plugins, function($plugin) use ($author) { return $plugin['Author'] === $author; }); // Display the filtered mu-plugins foreach ($filtered_plugins as $plugin) { echo 'Plugin Name: ' . $plugin['Name'] . '<br>'; }