Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ChuckMac/4636464 to your computer and use it in GitHub Desktop.
Save ChuckMac/4636464 to your computer and use it in GitHub Desktop.
WordPress plugin depency check. Check if another plugin is installed before allowing yours to be installed
/**
* Activation Class
**/
if ( ! class_exists( 'WC_CPInstallCheck' ) ) {
class WC_CPInstallCheck {
static function install() {
/**
* Check if WooCommerce & Cubepoints are active
**/
if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ||
!in_array( 'cubepoints/cubepoints.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
// Deactivate the plugin
deactivate_plugins(__FILE__);
// Throw an error in the wordpress admin console
$error_message = __('This plugin requires <a href="http://wordpress.org/extend/plugins/woocommerce/">WooCommerce</a> &amp; <a href="http://wordpress.org/extend/plugins/cubepoints/">Cubepoints</a> plugins to be active!', 'woocommerce');
die($error_message);
}
}
}
}
register_activation_hook( __FILE__, array('WC_CPInstallCheck', 'install') );
@dumketo
Copy link

dumketo commented Jan 26, 2018

it also shows error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment