Automatically install wordpress plugin at theme activation

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

Leave a Comment