Last active
July 12, 2021 22:51
-
-
Save otakupahp/8eb05ebcd2392e51452230d66a1a1d1a to your computer and use it in GitHub Desktop.
Simple function to check a plugin activation
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
<?php | |
/** | |
* @since 1.0.0 | |
* | |
* @param $plugin_name | |
*/ | |
public static function activate($plugin_name) { | |
# Initialize variables | |
$error_message = ''; | |
# Check for Woocommerce | |
if( is_plugin_active('woocommerce/woocommerce.php') ) { | |
global $woocommerce; | |
$wc_version = $woocommerce->version; | |
$wp_version = get_bloginfo( 'version' ); | |
$php_version = phpversion(); | |
/** | |
* Minimum requirements: | |
* | |
* - PHP 7.2 | |
* - WP 5.0 | |
* - WC 5.0 | |
*/ | |
if( version_compare( $php_version, '7.2', '>=' ) && version_compare( $wp_version, '5.0', '>=' ) && version_compare( $wc_version, '5.0', '>=' ) ) { | |
# Some cool activation text | |
} | |
else { | |
$error_message = __('This plugin works with PHP 7.2 or higher, Wordpress version 5.0 or higher and Woocommerce version 5.0 or higher', $plugin_name); | |
} | |
} | |
else { | |
$error_message = __('You need to have Woocommerce installed and activated to use this plugin', $plugin_name); | |
} | |
# Prevent activation in case of errors | |
if( !empty($error_message) ) { | |
# Deactivate the plugin | |
deactivate_plugins(plugin_basename( __FILE__ )); | |
die($error_message); | |
} | |
} |
If you need a specific plugin or plugins to activate this plugin, change line 14 to check the propper plugin path.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This plugin checks these minimum requirements: