Class Name:

MP_CORE_Plugin_Checker

Purpose:

To allow a plugin or theme to require outside plugins and automatically install them.

Overview:

This class uses associative arrays to determine which plugins are required and where to fetch them from. If the plugin is available from the WordPress.org Plugin Repository, it will download it from there. If it is not, it will secondarily check from a URL to the plugin ZIP file.

It will automatically download and activate the plugin when the user clicks “Install”, or in the case they already have the plugin installed but not activated, they would click “Activate”. That message is automatically displayed based on whether the plugin in installed or not.

There are 2 ways to check for a plugin. Either as part of a ‘group’ or singularly. If the plugin is checked as part of a group, it will show in the dashboard with a button that says “Install All Items”. The purpose of this is to reduce the amount of clutter in the user’s dashboard for plugins that do not need to be outlined individually.

If the plugin is checked singularly, it will have its own notice in the user’s dashboard.

Usage:

To include a plugin, you will hook into ‘mp_core_check_plugins’ filter hook. This will add your plugin to the list of plugins that need to be installed.

Example:


function my_plugin_check( $plugins ) {
		
	$add_plugins = array(
		array(
			'plugin_name' => 'My Plugin',
			'plugin_message' => __('You require my plugin. Install it here.', 'textdomain'), 
			'plugin_filename' => 'my-plugin.php',
			'plugin_download_link' => 'http://mydomain.com/my-plugin.zip',
			'plugin_info_link' => 'http://myplugin.com/info-about-my-plugin',
			'plugin_group_install' => true,
			'plugin_required' => true,
			'plugin_wp_repo' => true,
		)
	);
		
	return array_merge( $plugins, $add_plugins );
}

add_filter( 'mp_core_check_plugins', 'mp_core_plugin_check' );

Sample Akismet Check:

This is a sample plugin check using the Plugin Checker class built into the Move Plugins Core. To use the class just sub in your desired plugin’s information. Here is an example using the Akismet plugin for spam:


/**
 * Install Akismet Plugin
 *
 */
function akismet_check() {
	$args = array(
           array(
		'plugin_name' => 'Akismet', 
		'plugin_message' => 'In order to keep your website from being overrun with spam, activate the Akismet Plugin. (Required).', 
		'plugin_filename' => 'akismet.php',
		'plugin_download_link' => 'http://my_website.com/akismet.zip',
                'plugin_info_link' => 'http://akismet.com/',
                'plugin_group_install' => true,
		'plugin_required' => true,
		'plugin_wp_repo' => true,
            )
	);
	return array_merge( $plugins, $add_plugins );
}
add_filter( 'mp_core_check_plugins', 'akismet_check' );

The array keys and values above are as follows:

  • plugin_name (string) – Name of plugin.
  • plugin_message (string) – Message which shows up in notification for plugin.
  • plugin_filename (string) – Name of plugin’s main file
  • plugin_download_link (string) – Link to URL where this plugin’s zip file can be downloaded
  • plugin_info_link (string) – Link to URL containing info for this plugin
  • plugin_required (bool)(optional)(defaults to false) – If false allows plugin notice to be dismissed
  • plugin_group_install (bool)(optional)(defaults to true) – Whether to install this plugin with “the group” or on it’s own
  • plugin_wp_repo (bool)(optional)(defaults to true) – Whether to look for this plugin on the WP Repo or not