Created
January 25, 2013 17:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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> & <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') ); |
hi,
you can check if another plugin is installed with this method is_plugin_active
.
In your example, we have something like this
``
/**
- Activation Class
/
if ( ! class_exists( 'WC_CPInstallCheck' ) ) {
class WC_CPInstallCheck {
static function install() {
/
* Check if WooCommerce & Cubepoints are active
**/
if ( !is_plugin_active('woocommerce/woocommerce.php'))
// 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> & <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') );
``
it also shows error
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this show a message "Plugin could not be activated because it triggered a fatal error." prior to your output?