Loading Plugins From Your Theme

As of today, you can now use wpcom_vip_load_plugin() to load plugins that are bundled within your theme!

For WordPress.com

This is a follow-up to the recent shared plugins changes, in which some plugins were “deprecated” and moved to our reviewed plugins list. Some of you have already begun moving reviewed plugins into your themes and using require() to load them.

We realised that in making this change we’d overlooked the wpcom-helper.php files that we included in these plugins. By moving them to your themes and using require(), the helper files were no longer being loaded. We considered two options to resolve this;

  1. Have themes also manually require the wpcom-helper.php file
  2. Support theme-bundled plugins in wpcom_vip_load_plugin()

By far the most consistent and pain-free experience would be the second option, and that’s what we’re releasing today. Here’s how it works;

  • In your theme you can now create a plugins folder: theme-name/plugins
  • Within that theme you can place the plugins you would like to use, e.g.; theme-name/plugins/mce-table-buttons
  • That plugin might include a wpcom-helper.php: theme-name/plugins/mce-table-buttons/wpcom-helper.php
  • Now you can load that plugin with wpcom_vip_load_plugin( 'mce-table-buttons', 'theme' );

As you can see from the example above, the second parameter of wpcom_vip_load_plugin() now takes “theme” as a value. When this happens the function looks in the currently active theme for a plugins folder containing a plugin with the name specified. As a fallback, it will also search the parent theme (where applicable) and the shared plugins repository.

For those of you who have already moved plugins into your theme and used require() we will be in touch shortly with a patch to move you to this new method for your convenience.

What about custom shared plugins directories?

If you’re already using your own shared plugins directory (e.g. acme-plugins) nothing changes for you. You can still continue to load plugins in exactly the same way.

For VIP Go

On VIP Go we recommend that plugins are added to your plugins directory, and that you activate them using the wpcom_vip_load_plugins function rather than by using the WordPress plugins UI in the admin area. This ensures that your site code will function in a similar fashion across your different environments (e.g. local development environment, staging site, production site, etc).