Created
April 1, 2019 16:47
-
-
Save tradesouthwest/a9e5158cbc560725d0b7779f8c8679b0 to your computer and use it in GitHub Desktop.
prevents theme activation on a server that's PHP version is below 5.6.
This file contains hidden or 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 | |
/** | |
* Set a constant that holds the theme's minimum supported PHP version. | |
*/ | |
define( 'THEMESLUG_MIN_PHP_VERSION', '5.6' ); | |
/** | |
* Immediately after theme switch is fired we we want to check php version and | |
* revert to previously active theme if version is below our minimum. | |
*/ | |
add_action( 'after_switch_theme', 'themeslug_test_for_min_php' ); | |
/** | |
* Switches back to the previous theme if the minimum PHP version is not met. | |
*/ | |
function themeslug_test_for_min_php() { | |
// Compare versions. | |
if ( version_compare( PHP_VERSION, THEMESLUG_MIN_PHP_VERSION, '<' ) ) { | |
// Site doesn't meet themes min php requirements, add notice... | |
add_action( 'admin_notices', 'themeslug_min_php_not_met_notice' ); | |
// ... and switch back to previous theme. | |
switch_theme( get_option( 'theme_switched' ) ); | |
return false; | |
}; | |
} | |
/** | |
* An error notice that can be displayed if the Minimum PHP version is not met. | |
*/ | |
function themeslug_min_php_not_met_notice() { | |
?> | |
<?php | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment