Last active
July 10, 2018 08:51
-
-
Save dartiss/033979e29641313cfa9491bf42a3a256 to your computer and use it in GitHub Desktop.
Check for a minimum level of PHP and stop activation if the current host is below this
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 | |
function check_php_level() { | |
$php = '[[your minimum PHP level]]'; // Minimum PHP level required | |
/* translators: %1$s: required PHP version, %2$s: current PHP level */ | |
$message = sprintf( __( 'The [[your plugin name]] plugin requires PHP version %1$s or greater but you are using version %2$s. The plugin has NOT been activated.', '[[your text-domain]]' ), $php, PHP_VERSION ); | |
$title = __( 'Plugin Activation Error', '[[your text-domain]]' ); | |
if ( version_compare( PHP_VERSION, $php, '<' ) ) { | |
wp_die( esc_html( $message ), esc_html( $title ) ); | |
} else { | |
return; | |
} | |
} | |
register_activation_hook( __FILE__, 'check_php_level' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple function, to add to a WordPress plugin, to check for the current level of PHP and fail activation if the current hosting environment is less than the one that's required for the plugin to run.
Replace all content contained within double square brackets before using.