Automatically install wordpress plugin at theme activation

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.

Read More

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?

Related posts

2 comments

  1. 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

  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

Comments are closed.