Forked from joelworsham/gist:ca39eeacace703c368a4
Last active
January 11, 2016 01:20
-
-
Save rheinardkorf/2a0a64a7a976e36b9656 to your computer and use it in GitHub Desktop.
PHP Version Check
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 | |
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