WordPress MU Plugins: A Must Use


If you have used WordPress CMS for even a short period of time, you probably encounter the directory "mu-plugins"? At first I didn't bother asking myself what it is for but thanks to the post of Greg Rickaby, I was enlightened of its purpose. It wasn't just a decoration; it was there for a reason.

What is MU Plugins?

MU plugins stands for "Must Use" plugins. These are plugins installed in a specified directory, in this case it’s the mu-plugins directory as the default under the wp-content directory.

These plugins are enabled automatically on all sites in the installation. It doesn’t show in the list of plugins in the admin plugin’s page – it does have a section called Must-Use section and cannot be disabled unless you remove the plugin file in the must-use directory.

You can change the default directory by setting the WPMU_PLUGIN_DIR and WPMU_PLUGIN_URL in wp-config.php.

Pros and Cons

Pros

  • MU plugins are always enable, no need to activate via admin and cannot be disable by accident.
  • Can be enabled simply by uploading the plugin file in the mu-plugins directory.

Cons

  • MU plugins cannot be updated via admin dashboard. It doesn’t show you notifications of updates.
  • Activation hooks are not executed in plugins added in the mu-plugins directory.
  • WP only looks for PHP files right inside the mu-plugins directory, meaning, if you have a plugin called “My Awesome Plugin” and you put it inside a directory (so you can organized the plugin files) called “my-awesome-plugin”, you need to have a loader php file that will call load “my-awesome-plugin”.
Example:

If you have “load.php” file directly under the mu-plugins directory. Your code might be;

require WPMU_PLUGIN_DIR. ‘/my-awesome-plugin/ my-awesome-plugin.php’;

Origin

A little history about MU plugins, it was originally implemented for WPMU (Multi-User) to offer site admins to manage plugins on all blogs in the farm. It was then merge in the main WordPress code on 03/07/09.

No comments:

Post a Comment