Bundling Plugins with Themes
In WordPress, custom functionality can be included in plugins and in theme code. Many themes come with PHP code that adds functionality. To make themes less bloated and feature rich, we recommend that complicated functionality be included in plugins and not be part of the theme code.
Themes can then include plugins, which will be installed when the theme is activated. This approach has several key advantages:
- Richer functionality: plugin code can run at times when theme code cannot execute (like in the admin panel).
- More standard functionality: Multiple themes can use the same plugins and provide a more consistant user experience.
- Easier theme design: By using existing functionality from plugins, theme design can be significantly simplified.
- Automated updates: WordPress can automaitcally update plugins, helping websites remain up-to-date and more secure.
How to include plugins with themes?
We’ve created a function that can be included in any theme which will automatically install and activate plugins. In order for this function to work correctly, the wp-contents/plugins directory must be writable by the web server (same requirement as for the auto-plugin update feature in WordPress).
Add the function to your theme
Download the iclt-resources.zip code. This ZIP file includes the PHP functions that will extract and deploy the included plugins.
Unzip it and copy the folder ‘iclt-resources’ into the theme folder root.
Include the plugins that need to be deployed
- In the ‘functions.php’ file of the template add this line at the end:
<?php include TEMPLATEPATH . '/iclt-resources/iclt-deploy.php'; ?>
- Add the plugins ZIP files in iclt-resources/iclt-plugins
- Add plugins information in iclt-resources/iclt-plugins/iclt-plugins.txt (on separate lines)
plugin-archive.zip > [plugin-folder/]plugin-file.php
- ‘plugin-folder’ has to match the plugin folder name from the archive.
- ‘plugin-file.php’ is the name of the plugin ‘core’ file.
e.g. for a one file plugin:
plugin-archive.zip > plugin-file.php
How does it work?
When a user activates a theme that has bundled functions, the theme will attempt to install and activate the included plugins. Install will happen when the theme is displayed for the first time by a logged-in administrator.
If the theme cannot write to the plugins folder, it will issue a warning. You can change the folder write permissions and try again (just refresh the page).
Once installed, the theme will not attempt to update or reinstall plugins. The user can use the standard WordPress plugin management to update the plugins.
English
Deutsch
Español