Must-use plugins (a.k.a. mu-plugins) are plugins installed in a special directory inside the content folder and which are automatically enabled on all sites in the installation. Must-use plugins do not show in the default list of plugins on the Plugins page of wp-admin – although they do appear in a special Must-Use section – and cannot be disabled except by removing the plugin file from the must-use directory, which is found in wp-content/mu-plugins by default.
To change the default directory manually, define WPMU_PLUGIN_DIR
and WPMU_PLUGIN_URL
in wp-config.php.
Despite its suitability for many special cases, the mu-plugins system is not always ideal and has several downsides that make it innapropriate in certain circumstances. Below are several important caveats to keep in mind:
<?php // mu-plugins/load.php require WPMU_PLUGIN_DIR.'/my-plugin/my-plugin.php';
The 'mu-plugins' directory was originally implemented by WPMU (Multi-User) to offer site admins an easy way to activate plugins by default on all blogs in the farm. There was a need for this feature because at the time the multi-user-specific code did not offer ways of achieving this effect using the site admin section (today the renamed "Multisite WordPress" has features to manage plugins from inside the admin).
The code handling /mu-plugins/ was merged into the main WordPress code on 03/07/09 with this changeset a full 10 months before the wpmu codebase was initially merged, and all WP sites could take advantage of autoloaded plugins, whether they had MU/Multisite enabled or not. The feature is useful for all types of WP installations depending on circumstances, so this makes sense.
In this process the name "mu plugins" became a misnomer because it did not apply exclusively to multisite installs and because "MU" was not even being used anymore to refer to WP installations with multiple blogs. Despite this, the name was kept and re-interpreted to mean "Must-use plugins", i.e. These are plugins that must always be used, thus they are autoloaded on all sites regardless of the settings in the Plugins pane of wp-admin.
Thus "Must-Use" is effectively a Backronym, like PHP (which originally meant "Personal Home Page" but was later re-interpreted as meaning "PHP Hypertext Preprocessor", which is also a Recursive Acronym).
Create a file mu-autoloader.php within the mu-plugins directory /mu-plugins/mu-autoloader.php and put the following contents into it:
<?php /** * Plugin Name: Must Use Plugins Autoloader * Plugin URI: https://codex.wordpress.org/Must_Use_Plugins * Description: This Plugin is loading all plugins within folder in the /mu-plugins directory. For more details please have a look into your /wp-content/mu-plugins folder. * Author: WordPress Codex */ $dirs = glob(dirname(__FILE__) . '/*' , GLOB_ONLYDIR); foreach($dirs as $dir) { if(file_exists($dir . DIRECTORY_SEPARATOR . basename($dir) . ".php")) { require($dir . DIRECTORY_SEPARATOR . basename($dir) . ".php"); } }
This will load all Plugins within this directory just like you would be within the normal Plugins directory. Please note the other restrictions on MU Plugins described within this article.
get_mu_plugins()
is located in wp-admin/includes/plugin.php
.wp_get_mu_plugins()
is located in wp-includes/load.php
.