Skip to content

Instantly share code, notes, and snippets.

@rheinardkorf
Forked from joelworsham/gist:ca39eeacace703c368a4
Last active January 11, 2016 01:20
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 rheinardkorf/2a0a64a7a976e36b9656 to your computer and use it in GitHub Desktop.
Save rheinardkorf/2a0a64a7a976e36b9656 to your computer and use it in GitHub Desktop.
PHP Version Check
<?php
class MyPlugin {
/**
* Add this at top of your plugin class constructor or whichever method in your class you use to bootstrap your plugin.
* e.g. public static function bootstrap()
*/
public static function bootstrap() {
if ( version_compare( '5.3', phpversion(), '>' ) ) {
add_action( 'admin_notices', array( __CLASS__, 'php_version_notice' ) );
return; // Exit method before doing other cool things
}
}
/**
* Hooks `admin_notices`. Must echo to be useful.
*/
public static function php_version_notice( $echo = true ) {
$content = '<div class="error"><p>' . esc_html__( 'MYPLUGIN is not active because your server is not running at least PHP version 5.3. Please update or contact your server administrator.', 'textdomain' ) . '</p></div>';
if ( $echo )
echo $content;
return $content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment