2
votes

I am developing a WordPress theme, i have downloaded and installed the "contact form 7" plugin. Now when i send this theme to my client and they install/activate the theme, i would like the "contact form 7" plugin to be included.

I haven't got access to their wp-admin and i can't expect them to manually install the plugins. So to make it easier for them, i'd like to package the plugins with the theme. Then they install and everything works correctly.

How do i do this or is there a better way e.g. recommend installing a plugin?

2

2 Answers

2
votes

You will want to use some variant of the following:

function my_activate_theme() {

    $plugins = array(
        "plugin_name_1",
        "plugin_name_2",
        "etc..."
    );

    foreach ($plugins as $plugin) {
        $path = '/path/to/wordpress/wp-content/plugins/{$plugin}.php';
        activate_plugin($path);
    }
}

add_action('switch_theme', 'my_activate_themes');

You will have to fiddle around with my code, as I don't have access to a wordpress install at the moment to test on, but basically the idea is that you throw this into your functions.php file. It registers the hook for switching theme and on theme switch, loops through the specified plugins and activates them.

I hope this helps, if not, please give me more information and I will attempt to provide further guidance. Good luck!

0
votes

If you are currently developing theme, you'd rather use tgm activation code than including plugins into your theme.


Please review this Wordpress Theme.

This theme use tgm activation code to install "Visual Composer","Layerslider","Revslider","Quickshop" plugins.

It's much easier to customize and has lots of features. Also easy to learn code tips.

Regards. HanaTheme.