I’m working on a theme that includes some functionality I’ve developed as separate plugins (as I’m hoping to release them independently).
I’d like to include these plugins as part of the theme core and I’ve noticed that some developers include plugins as files or subdirectories along with their theme, but over time that can ultimately lead to maintaining two versions of the same plugin – one for the plugin repository, one for the theme – but I’d like to avoid that, if possible.
What’s the best practice for including plugins as part of a theme?
If you plan to release them independently, then release them independently and try to get them both hosted in the WP repository. This will allow you to update the systems remotely and keep people using the most up-to-date system possible.
Then, in your theme, use
is_plugin_active()
to filter your commands. If you have a theme feature that requires a plugin, useis_plugin_active()
to dynamically switch between using the feature or nagging the user to install the plugin.The important thing to keep in mind is that your theme should still work if the plugins aren’t installed. It doesn’t have to have the same rich feature set, but it also shouldn’t break if they decide to remove or deactivate one of the other plugins.
Alternatively, if you know that a certain plugin isn’t going to change for a very long time (I use a few plugins that only add/remove specific WP filters) you can drop the
PHP
file into a/library
directory with your theme andinclude()
the file infunctions.php
. Then the functionality is enabled by default – tradeoff is that you’re now maintaining two versions of the plugin (as you mentioned in your original question).Basically you have three possible cases:
Take in account which is more likely to get updated:
So overall it is good idea to keep code same (similar, if not identical) and load it in theme conditionally when plugin is not present. Because as it is now plugins are both easier and more common to update.
Obviously theme must be able to make use of bundled or separate plugin either and plugin shouldn’t depend on code from theme at all.
Best (but complex practice) is building your extensions as context-independent (aka framework) and use custom loader to check for versions and load latest available. For practical example of framework approach see scbFramework which is both distributed as separate plugin and used in multiple other plugins.