Created
January 26, 2019 02:01
-
-
Save seothemes/55657327805c839e2a0aaef6fd394218 to your computer and use it in GitHub Desktop.
Compatibility checker functions
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 | |
| add_action( 'plugins_loaded', 'compat_checker_deactivate' ); | |
| /** | |
| * Description of expected behavior. | |
| * | |
| * @since 1.0.0 | |
| * | |
| * @return void | |
| */ | |
| function compat_checker_deactivate() { | |
| if ( ! compat_checker_is_compatible() ) { | |
| add_action( 'admin_init', 'compat_checker_deactivate_plugin' ); | |
| add_action( 'admin_notices', 'compat_checker_deactivate_notice' ); | |
| } | |
| } | |
| /** | |
| * Description of expected behavior. | |
| * | |
| * @since 1.0.0 | |
| * | |
| * @return void | |
| */ | |
| function compat_checker_deactivate_plugin() { | |
| deactivate_plugins( plugin_basename( plugin_dir_path( __DIR__ ) . '/compat-checker.php' ) ); | |
| } | |
| /** | |
| * Description of expected behavior. | |
| * | |
| * @since 1.0.0 | |
| * | |
| * @return void | |
| */ | |
| function compat_checker_deactivate_notice() { | |
| echo '<div class="notice notice-warning"><p>' . wp_kses_post( compat_checker_deactivate_message() ) . '</p></div>'; | |
| } | |
| /** | |
| * Description of expected behavior. | |
| * | |
| * @since 1.0.0 | |
| * | |
| * @return bool | |
| */ | |
| function compat_checker_deactivate_message() { | |
| if ( version_compare( PHP_VERSION, '5.4', '<' ) ) { | |
| // Translators: 1 is the required PHP version and 2 is the user's current version. | |
| return sprintf( | |
| __( 'The <strong>Compat Checker</strong> plugin requires at least PHP version %1$s to run. This site uses %2$s, so the plugin has been <strong>deactivated</strong>.', 'compat-checker' ), | |
| '5.4', | |
| PHP_VERSION | |
| ); | |
| } elseif ( version_compare( $GLOBALS['wp_version'], '5.0.0', '<' ) ) { | |
| // Translators: 1 is the required WordPress version and 2 is the user's current version. | |
| return sprintf( | |
| __( 'The <strong>Compat Checker</strong> plugin requires at least WordPress version %1$s. You are running version %2$s, so the plugin has been <strong>deactivated</strong>.', 'compat-checker' ), | |
| '5.0.0', | |
| $GLOBALS['wp_version'] | |
| ); | |
| } elseif ( 'Genesis' !== wp_get_theme()->parent()->Name ) { | |
| return sprintf( | |
| __( 'Sorry, you cannot run the <strong>Compat Checker</strong> plugin without an active Genesis child theme. Please install and activate a Genesis child theme and try again.', 'compat-checker' ) | |
| ); | |
| } elseif ( version_compare( wp_get_theme()->parent()->Version, '2.8.0', '<' ) ) { | |
| // Translators: 1 is the required Genesis version and 2 is the user's current version. | |
| return sprintf( | |
| __( 'The <strong>Compat Checker</strong> plugin requires at least Genesis version %1$s. You are running version %2$s so the plugin has been <strong>deactivated</strong>.', 'compat-checker' ), | |
| '2.8.0', | |
| wp_get_theme()->parent()->Version | |
| ); | |
| } | |
| return false; | |
| } | |
| /** | |
| * Description of expected behavior. | |
| * | |
| * @since 1.0.0 | |
| * | |
| * @return bool | |
| */ | |
| function compat_checker_is_compatible() { | |
| return compat_checker_deactivate_message() === false ? true : false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment