Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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, use is_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 and include() the file in functions.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).

share|improve this answer
add comment

Basically you have three possible cases:

  • theme and plugin both installed;
  • only theme is installed;
  • only plugin is installed.

Take in account which is more likely to get updated:

  • repository-hosted plugin - likely;
  • repository-hosted theme - likely;
  • not repository-hosted theme or plugin - unlikely;
  • child theme - highly unlikely (can't be hosted in repository, manual merge of changes because it's meant to be customized by end-user).

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.