Advertisement
  1. Code
  2. WordPress
Code

Ever Heard of Must-Use Plugins?

by
Difficulty:BeginnerLength:ShortLanguages:

WordPress has loads of functions, tools and utilities in its core, many of which are what contribute to making WordPress the number one content management system in the world.

Most of these WordPress features are well known—like custom post types, action and filter hooks, and the visual editor—but some of them aren't necessarily as "famous" as others. In this article, we're going to talk about one of the lesser known (yet extremely useful) features of WordPress: must-use plugins.

What Are Must-Use Plugins?

It's not unnatural that the must-use plugins feature is overlooked, since it was introduced in WPMU (WordPress Multi-User), and WPMU wasn't integrated into WordPress Core until WordPress 3.0. Back then, the folder named mu-plugins offered the ability for network admins to activate a plugin on every blog in the network. After the merge in WordPress 3.0, the "mu-plugins" directory stayed, and its name was (according to the Codexre-interpreted to mean "must-use plugins".

Main Features of Must-Use Plugins

There are advantages and disadvantages for must-use plugins—let's check them out:

They're always on: In essence, must-use plugins are the plugins that must be used and autoloaded in your WordPress website (or network).

You can't disable them: Even if you're an administrator, you can't disable or delete must-use plugins. You can, however, delete them from the mu-plugins directory (which is under wp-content, by the way). You also can't install new plugins there—you have to upload them manually into the directory.

They're loaded before normal plugins: The plugins inside the mu-plugins directory are loaded before the plugins inside the plugins directory. Interestingly, must-use plugins are loaded in alphabetical order.

You can't use activation/deactivation hooks: This one is self-explanatory—since must-use plugins are auto-activated and can't be de-activated or uninstalled, you can't use activation or deactivation hooks for them.

They don't update: The plugins inside the mu-plugins directory don't update automatically, and WordPress doesn't notify you about new versions. This means that you have to keep them up-to-date manually.

You have to use PHP files: WordPress doesn't look inside the folders in the mu‑plugins directory—you must place PHP files in the directory's root. Don't worry, though: You can create a proxy PHP file and require the main files in plugins' folders.

Ideas on Where They Can Be Used

There can be many uses for must-use plugins, whether they be clever and creative or just to save the day. Let's check out some cases that I could come up with—if you have an idea, don't forget to share it with us!

Using Must-Use Plugins on Multisite Networks

Multisite networks are the reason why the mu-plugins directory exists, so I put this idea on top of the others.

While it might be a better idea if you just use the "network activation" feature, you could use must-use plugins if you need more power. There are various differences between network-activated plugins and must-use plugins (which are explained in this very old blog post) and some of them might work for your network.

Using Must-Use Plugins on Client Websites

If you give (or must give) access to the administrator account for your clients, they might tend to play with settings, theme options, plugins, and any other page they have access to. And when they try to deactivate (and worse, delete) some plugin, they might tend to call you on a Saturday night and confess their sins—or blame you for not maintaining the website. 

If you move all the plugin folders to the mu-plugins directory and create a PHP file to require those plugins' main files, your client will not be able to deactivate those plugins. But be warned: You won't be able to get automatic updates!

Using Must-Use Plugins for Site-Specific Plugins

This one is my favorite use for must-use plugins.

If you have a website that needs some crucial functionality, the right thing to do would be to create a site-specific plugin. Because you can't bear even an accidental deactivation of your site-specific plugin, you'd better move it to the mu-plugins directory so that even you can't disable it. And since you're the developer and you don't use the plugin anywhere else, there won't be any plugin updates.

Conclusion

In this article, I wanted to tell you about one of the most underrated (and generally unknown) features of WordPress. I was truly and utterly shocked when I found out about must-use plugins, and I hope you're shocked as well. We can definitely use must-use plugins in more areas than the ones I came up with, but these alone could make huge differences with your WordPress websites.

Do you agree that must-use plugins are useful? Can you think of more cases for using must-use plugins? Tell us what you think by commenting below. And if you liked this article, don't forget to share it with your friends!

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.