check php and wordpress version before activation

Solutions on MaxInterview for check php and wordpress version before activation by the best coders in the world

showing results for - "check php and wordpress version before activation"
Elizabeth
02 Mar 2018
1register_activation_hook(__FILE__, 'check_version');
2function check_version() {
3    $php_version_required = '5.6';
4    $wp_version_required  = '4.8';
5    
6    if ( version_compare( PHP_VERSION, $php_version_required, '<' ) ) {
7        deactivate_plugins( basename(__FILE__) );
8		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 ));
9    }
10    
11    if ( version_compare($wp_version, $wp_version_required, '<') ) {
12        deactivate_plugins( basename(__FILE__) );
13		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 ));
14    }
15}
similar questions