Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Plugin Checker for the WP customizer. Drop it in your themes!
<?php
/**
* Plugin Check for the WP customizer
* Inspired by http://ottopress.com/2012/themeplugin-dependencies/ & http://ottopress.com/2013/slides-a-presentation-theme/
*
* Of Desks Studio Inc.
*
* Example:
$wp_customize->add_section( 'plugins', array(
'title' => __( 'Recommended Plugins', 'theme_name' ),
) );
$wp_customize->add_setting( 'recommended_plugin');
$wp_customize->add_control( new Of_Customize_Plugin_Check_Control( $wp_customize, 'recommended_plugin', array(
'section' => 'plugins',
'settings' => 'recommended_plugin',
'plugins' => array (
'wp-org-slug' => 'plugin_dir/plugin_file.php',
'media-ep' => 'media-ep/media-ep.php',
)
) ) );
*/
if ( class_exists( 'WP_Customize_Control' ) ) :
class Of_Customize_Plugin_Check_Control extends WP_Customize_Control {
/**
* @access public
* @var array
*/
public $plugins = array();
/**
* @access private
* @var array
*/
private $installed_plugins;
/**
* Render Tool Tip
*
* Set "plugins" to display your tool tip.
*
* @return void
*/
public function render_content() {
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$this->installed_plugins = get_plugins();
foreach ( $this->plugins as $plugin_slug => $plugin_file ) {
$plugin_info = plugins_api( 'plugin_information', array( 'slug' => $plugin_slug ) );
if ( ! is_wp_error( $plugin_info ) ) {
if ( ! isset( $this->installed_plugins[$plugin_file] ) ) {
// Is it installed?
echo '<div class="error">';
echo "<p>{$plugin_info->name} is <strong>not installed</strong></p><p><strong><a href=\"" . wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $plugin_slug ), 'install-plugin_' . $plugin_slug ) . '">Install it</a></strong></p>';
echo '</div>';
} else if ( is_plugin_inactive( $plugin_file ) ) {
// Is it activated?
echo '<div class="error">';
echo "<p>{$plugin_info->name} is <strong>installed</strong></p><p><strong><a href=\"" . wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $plugin_file ), 'activate-plugin_' . $plugin_file ). '">Activate it</a></strong></p>';
echo '</div>';
} else {
// Must be good!
echo '<div class="updated">';
echo "<p>{$plugin_info->name} is <strong>activated</strong></p>";
echo '</div>';
}
}
}
}
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.