Automatically Install WordPress Plugins when Your Theme is Installed

The thought of making a wordpress theme and requiring users to install plugins needed to make it work sounds pretty sucky. The thought of taking plugins and hardcoding them into my theme sounds even suckier. …And I hate things that suck. So here is how you can automatically install wordpress plugins when your theme loads:

Put this in functions.php or a file included by functions.php.


install_theme_plugins(array('my-plugin' => 'path-to-main-file.php'));

function install_theme_plugins($plugins)
{
foreach($plugins as $dir=>$file)
{
include ABSPATH.'/wp-admin/includes/plugin.php';
activate_plugin($dir.DS.$file);
}
}

Tomorrow I’ll add a script that checks the plugin server to see if the version is the latest (and if so) downloads a new one, and then activates it, when you install the theme. Cheers.

Oh, one thing to keep in mind. This: array(‘my-plugin’ => ‘path-to-main-file.php’) actually has to refer to a path that exists in your plugin directory. Just in case ; )

This entry was posted in PHP, Wordpress. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted August 13, 2011 at 7:54 am | Permalink

    I hate things that suck. – CALVIN FROEDGE

  2. Darren Robinson
    Posted August 22, 2011 at 11:17 am | Permalink

    Me and my friend were arguing about an issue similar to this! Now I know that I was right. lol! Thanks for the information you post.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>