Installing Plugins Automatically in a Premium WordPress Theme

I think those who have ever downloaded WordPress themes or bought them on exchanges such as themeforest, noticed that after installation and activation, many themes ask you to install the necessary plugins for them. Today we will talk about the library TGM Plugin Activation which allows you to install plugins after activating the theme, learn how in premium themes all plugins are set automatically. Plugins can be installed both from the WordPress repository, and other external sources, it will also be possible to install plugins that you developed and put in your theme. This library class installs and activates plugins based on the WordPress API., which means that there should be no problems with the update.

How to set up TGM Plugin Activation

We will carry out the settings on the standard TwentyEleven theme, but you can use another theme, check only that in your theme in style.css file, comment has been added: Text Domain: twentyeleven. Below in the skin we will use it in a variable $theme_text_domain = ‘twentyeleven’;.

First we need to download the library from developer site or from GitHub and put the file in the root of our theme class-tgm-plugin-activation.php and folder plugins with all its contents.

After the necessary files are copied, we need to connect our class to the template. We connect the class through a file functions.php.

To the functions.php file, at the top of it, add the code for calling the function to install required plugins:

Below we add the code of the function itself:

If you did everything right, you will see a message saying, what plugins need to be installed, required for this topic., message will look like this.

wordpress auto install plugin with themes

Click on the button Begin installing plugins and you will see a window with a list of your plugins.

wordpress auto install plugin with themes windowIn the window we can see, that the Edit Howdy item appears as a link, by clicking you will be able to read about this plugin, since we install it from the repository. Other plugins will be inactive, since they will be installed from the theme folder.

Let's start the automatic installation of plugins

  • Select plugins to install,
  • Select the action "install",
  • Click Apply.

auto install plugin step by step lwssons

If everything was done right, then you have 2 plugins will be installed and one will display an error (An error occurred while installing Evanto dashboard: Download failed. Invalid URL provided..). The error appeared because we did not add the Evanto dashboard plugin file to our theme.

autoinstall plugin to wordpress api

It remains only to mark all the necessary plugins and activate them.

wordpress plugin auto install and activate

If everything was done right, then you will get a message (The following plugins were activated successfully: Edit Howdy and TGM Example Plugin).

If you have not installed all plugins and decide to install one by one, while doing this you lost the installation window, then you can always return to the installation page through the admin menu in the section Appearance -> Install Plusins.

wordpress autoinstall plugin lessons

That's all, trying to install our plugins! Good luck in developing user-friendly and high-quality themes for WordPress.


Buy WordPress hosting
/* WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal