Answers for "Check php and wordpress version before activation"

PHP
0

Check php and wordpress version before activation

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 ));
    }
}
Posted by: Guest on September-07-2021

Code answers related to "Check php and wordpress version before activation"

Browse Popular Code Answers by Language