Skip to content

Instantly share code, notes, and snippets.

@joelworsham
Last active January 11, 2016 00:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joelworsham/ca39eeacace703c368a4 to your computer and use it in GitHub Desktop.
Save joelworsham/ca39eeacace703c368a4 to your computer and use it in GitHub Desktop.
PHP Version Check
<?php
...
if ( version_compare( '5.3', phpversion(), '>' ) ) {
add_action( 'admin_notices', '_myplugin_php_notice' );
// Do what you need to stop your plugin from loading
}
/**
* Displays an admin error about needing to update the server's PHP version.
*
* @access private
*/
function _myplugin_php_notice() {
?>
<div class="error">
<p>
<?php
sprintf(
__( 'MYPLUGIN is not active because your server is not running at least PHP version 5.3. Please update or contact your server administrator. (PS: PHP 5.3 is %s year\'s old!)', 'MYPLUGIN' ),
intval( date( 'y' ) ) - 9
)
?>
</p>
</div>
<?php
}
...
@joelworsham
Copy link
Author

Now, this won't work once enter the year 2100, but somehow I think that's okay!

@rheinardkorf
Copy link

Thanks!

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