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-plugins
directory within the WordPress content directory. Themu-plugins
directory will sit alongside your normalplugins
directory, normally atwp-content/mu-plugins
unless 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-plugins
won’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-plugins
directory 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-plugins
directory and then create aplugin-loader.php
file (any name will do) that does arequire
for the main plugin file. - Files in the
mu-plugins
directory load alphabetically. If you need to manually control the load order, you can simply rename the files. - You can move or rename the
mu-plugins
directory by setting these constants in yourwp-config.php
file:
define( 'WPMU_PLUGIN_DIR', __DIR__ . '/wp-content/required-plugins' );
define( 'WPMU_PLUGIN_URL', 'http://mydomain.com/wp-content/required-plugins' );