Created
August 30, 2018 16:36
-
-
Save k1sul1/e3c8ce5501d9ee0b652621cdf9379a46 to your computer and use it in GitHub Desktop.
WordPress: Block plugin activation if PHP or WordPress version is too low
This file contains hidden or 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 | |
register_activation_hook(__FILE__, function () { | |
$php_version = phpversion(); | |
$wp_version = $GLOBALS["wp_version"]; | |
$is_56 = version_compare($php_version, 5.6, ">="); | |
$is_70 = version_compare($php_version, 7.0, ">="); | |
$php_ok = $is_56 || $is_70; | |
$wp_ok = version_compare($wp_version, 4.7, ">="); | |
$message = ""; | |
if (!$php_ok) { | |
$message .= "Minimum PHP version required is 5.6. Yours is {$php_version}. "; | |
} elseif (!$wp_ok) { | |
$message .= "Minimum WP version required is 4.7. Yours is {$wp_version}. "; | |
} | |
if (!empty($message)) { | |
deactivate_plugins(basename(__FILE__)); | |
wp_die($message); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment