Skip to content

Instantly share code, notes, and snippets.

@dartiss
Last active July 10, 2018 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dartiss/033979e29641313cfa9491bf42a3a256 to your computer and use it in GitHub Desktop.
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
<?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' );
@dartiss
Copy link
Author

dartiss commented Jul 10, 2018

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.

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