WordPress must use plugins are plugins that are always loaded and cannot be deactivated within the WordPress admin.
Setup
A bit of a hidden feature, must use plugins require a little setup initially:
- First, you will need to create an
mu-pluginsdirectory within the WordPress content directory. Themu-pluginsdirectory will sit alongside your normalpluginsdirectory, normally atwp-content/mu-pluginsunless you’ve moved or renamed the WordPress content directory. - Then, any files you upload into that directory will be loaded automatically. Just be aware that dropping a folder into
mu-pluginswon’t do anything, only standalone files will load.
The Pros
- Must use plugins are always on and cannot be disabled within the admin area.
- Must use plugins load before normal plugins.
The Cons
- Must use plugins will never check for or show available updates.
- Must use plugins do not trigger plugin activation hooks.
Tips & Tricks
- Dropping a file into the
mu-pluginsdirectory means that code runs automatically, without having to log into the admin. This comes in handy when you need to do things like force a WordPress admin user. - If you want to load a normal plugin as a must use plugin, just drop the plugin folder into the
mu-pluginsdirectory and then create aplugin-loader.phpfile (any name will do) that does arequirefor the main plugin file. - Files in the
mu-pluginsdirectory load alphabetically. If you need to manually control the load order, you can simply rename the files. - You can move or rename the
mu-pluginsdirectory by setting these constants in yourwp-config.phpfile:
define( 'WPMU_PLUGIN_DIR', __DIR__ . '/wp-content/required-plugins' );
define( 'WPMU_PLUGIN_URL', 'http://mydomain.com/wp-content/required-plugins' );