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 looking into using http://tgmpluginactivation.com/ to activate required plugins for my custom theme during the theme activation step.

From what I can tell, this class only Activates plugins automatically, but it doesn't automatically Install plugins I have bundled with my theme.

Does anyone know if it's possible to automatically Install plugins upon theme activation? Preferably, in a way that can still make use of TGM?

share|improve this question
    
How are you bundling these plugins? Are they included in the download with instructions to add theme to wp-content/themes or are you including them in the theme's directory? –  JPollock Jul 19 '13 at 2:12
    
@JPollock they are packaged with the theme as individual zip files. TGM is configured to look at that directory when installing. Everything works fine when the user manually clicks the Install plugin link after theme activation, but I was looking for an automated way to install the plugins without any user action required. –  user387990 Jul 19 '13 at 10:06
add comment

2 Answers 2

The activate_plugin function should be what you're looking for. Place it in a after_setup_theme action.

Usage

activate_plugin ( $plugin, $redirect = '', $network_wide = false, $silent = false )

The doc. page for the activate_plugin function doesn't look too promising, and I have no idea if it will actually work, since I've never used it. I guess it's worth a shot?

I imagine activating plugins when a theme is activated could be potentially wreak havoc and break websites.

References

share|improve this answer
    
Surely making a plugin mandatory can make your theme weak, that is why there should be a fallback. In my previous answer I recommend you to use TMG plugin. So there is a option so that you can make a plugin required ( please check my Answer above as example ). If you just make the "required" to "false" you can overcome that situation. –  WpMania.Net Apr 13 at 22:35
add comment

Edited Answer:

TMG is a very popular auto plugin installer for WordPress and a lot of Premium theme author use it. You can get the php class here https://github.com/thomasgriffin/TGM-Plugin-Activation. Also when you will download it you will get a php file named example.php. You just have to include that example.php file in your function.php file and you just can edit that file to have auto installation for the required plugins for your theme.

You have to do something like this in the example.php file

// This is an example of how to include a plugin pre-packaged with a theme.
        array(
            'name'               => 'WpMania Slider', // The plugin name.
            'slug'               => 'WpmSlider', // The plugin slug (typically the folder name).
            'source'             => get_template_directory_uri() . '/assets/plugins/plugins/WpmSlider.zip', // The plugin source.
            'required'           => true, // If false, the plugin is only 'recommended' instead of required.
            'version'            => '', // E.g. 1.0.0. If set, the active plugin must be this version or higher.
            'force_activation'   => true, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch.
            'force_deactivation' => true, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins.
            'external_url'       => '', // If set, overrides default API URL and points to an external URL.
        ),

Thanks Sabbir

share|improve this answer
3  
Where would that array go? Not everyone is familiar with TMG, and what does it stand for? –  Tom J Nowell Apr 11 at 11:07
    
TMG is a very popular auto plugin installer for WordPress and a lot of Premium theme author use it. You can get the php class here github.com/thomasgriffin/TGM-Plugin-Activation. Also when you will download it you will get a php file named example.php. You just have to include that example.php file in your function.php file and you just can edit that file to have auto installation for the required plugins for your theme. –  WpMania.Net Apr 11 at 15:04
    
Nice, you should edit your answer to include that –  Tom J Nowell Apr 11 at 15:12
1  
I have updated the answer upon request –  WpMania.Net Apr 12 at 9:38
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.