📜  激活前检查 php 和 wordpress 版本 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:28.700000             🧑  作者: Mango

代码示例1
register_activation_hook(__FILE__, 'check_version');
function check_version() {
    $php_version_required = '5.6';
    $wp_version_required  = '4.8';
    
    if ( version_compare( PHP_VERSION, $php_version_required, '<' ) ) {
        deactivate_plugins( basename(__FILE__) );
        wp_die(sprintf( esc_html__( 'This plugin can not be activated because it requires a PHP version greater than %1$s. Please update your PHP version before you activate it.', 'OETFA-GOOGLE-2FA-RECAPTCHA' ), $php_version_required ), 'Error', array( 'back_link' => true ));
    }
    
    if ( version_compare($wp_version, $wp_version_required, '<') ) {
        deactivate_plugins( basename(__FILE__) );
        wp_die(sprintf( esc_html__( 'This plugin can not be activated because it requires a WordPress version greater than %1$s. Please go to Dashboard -> Updates to get the latest version of WordPress.', 'OETFA-GOOGLE-2FA-RECAPTCHA' ), $wp_version_required ), 'Error', array( 'back_link' => true ));
    }
}