While preparing the 3.0 release of Ajax Load More, I made a decision to create a new section for showcasing the available free extensions. I thought this was a good solution to help increase awareness of the plugins as site admins would now be able to browse all extensions in a centralized location without leaving their WordPress admin.

Then I thought a bit more and wondered what if site admins could install and activate the plugins from the very same section they are browsing – essentially, replicating the functionality found on the Add Plugins section works in the WordPress admin (as seen below).

If users could browse a curated set of plugins and install and activate each with only a few clicks – what type of impact would that have on overall downloads and active installs of these extension plugins?

I was fairly certain this type of functionality would lead to an increase in both downloads and active installs, so I set out to build a simple and re-useable class developers could drop into their plugins or themes.

Introducing the Connekt Plugin Installer

A lightweight PHP class for displaying a curated list of recommended or related plugins from directly inside of the WordPress admin.

Connekt Plugin Installer Example

The Connekt Plugin Installer allows site admins to install and activate plugins with as little as 2 clicks from the screen they are currently viewing inside of the WordPress admin.

This installation class is perfect for plugin and theme developers who want to make it as easy as possible for users to install recommended or related plugins directly inside their products.

Getting Started

To get started, you’ll simply need to download the package, copy the files to your plugin or theme directory, and then initialize the class. The installer provides all required JavaScript and CSS for functionality and display.

Class Loader

The first step is to load the class into your plugin or theme. This would typically appear in functions.php or in the _construct of your plugin Class.

include_once( 'vendor/connekt-plugin-installer/class-connekt-plugin-installer.php' );
PHP

Display

Next, you will build an array of plugin slugs and pass the array to the init method for display.

$plugin_array = array(
  array(
    'slug' => 'ajax-load-more',
  ),
  array(
    'slug' => 'instant-images'
  ),
  array(
    'slug' => 'block-manager'
  )
);

if ( class_exists( 'Connekt_Plugin_Installer' ) ) {
  Connekt_Plugin_Installer::init ($plugin_arra y);
}
PHP

Note: Plugins must be available for installation from the wordpress.org plugin repository.

And that’s pretty much it – when the init method is called, the class will render the plugin list and allow for direct plugin installation and activation!

Happy coding 🙂

Notes

  • Plugins must be available on the wordpress.org plugin repository to be installed and activated using this class.
  • Using this class outside of the /plugins directory will require modification to the CNKT_INSTALLER_PATH constant for loading assets – you can define this constant in functions.php prior to loading the class.
    define(‘CNKT_INSTALLER_PATH’, get_template_directory_uri() .’/vendor/connekt-plugin-installer/’)

Comments

2 thoughts on “WordPress Plugin Installer”

  1. Avatar

    Iftikhar

    September 29, 2020 @ 1:34 am
    Reply

    Thanks dear Darren,
    Thanks for the plugin installer.

    How about if I would like to bundle plugins with in the theme (not from wordpress.org repository.
    For example:
    mytheme/plugins/myplugin1/myplugin1.php
    mytheme/plugins/myplugin2/myplugin2.php

    Thanks in advance.
    Iftikhar

    1. Avatar

      Darren Cooney

      September 30, 2020 @ 7:45 am
      Reply

      Sure, you can do that.

Leave a Reply

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