@@ -871,8 +871,8 @@ public static function is_user_using_two_factor( $user = null ) {
871871
872872 // A WP_Error means the user has a provider enabled that's no longer registered. Still treat them as
873873 // "using" two-factor so the login requirement isn't dropped (failing open) just because their specific
874- // method disappeared.
875- return ! empty ( $ provider ) || is_wp_error ( $ provider ) ;
874+ // method disappeared. WP_Error is a non-null object, so !empty() already covers it.
875+ return ! empty ( $ provider );
876876 }
877877
878878 /**
@@ -1134,24 +1134,25 @@ public static function login_html( $user, $login_nonce, $redirect_to, $error_msg
11341134 if ( is_wp_error ( $ provider ) ) {
11351135 // The user's configured methods don't exist, and there was no replacement to swap in. This is the
11361136 // user's own login screen, so it's appropriate to stop here with a specific, actionable message.
1137- wp_die ( $ provider );
1137+ wp_die ( esc_html ( $ provider-> get_error_message () ) );
11381138 }
11391139 if ( ! $ provider ) {
11401140 wp_die ( esc_html__ ( 'Two-factor provider not available for this user. ' , 'two-factor ' ) );
11411141 }
11421142
11431143 $ provider_key = $ provider ->get_key ();
11441144 $ available_providers = self ::get_available_providers_for_user ( $ user );
1145- $ backup_providers = array_diff_key ( $ available_providers , array ( $ provider_key => null ) );
1146- $ interim_login = isset ( $ _REQUEST ['interim-login ' ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1147-
1148- $ rememberme = intval ( self ::rememberme () );
11491145
11501146 if ( is_wp_error ( $ available_providers ) ) {
11511147 // If it returned an error, the configured methods don't exist, and it couldn't swap in a replacement.
1152- wp_die ( $ available_providers );
1148+ wp_die ( esc_html ( $ available_providers-> get_error_message () ) );
11531149 }
11541150
1151+ $ backup_providers = array_diff_key ( $ available_providers , array ( $ provider_key => null ) );
1152+ $ interim_login = isset ( $ _REQUEST ['interim-login ' ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1153+
1154+ $ rememberme = intval ( self ::rememberme () );
1155+
11551156 if ( ! function_exists ( 'login_header ' ) ) {
11561157 // We really should migrate login_header() out of `wp-login.php` so it can be called from an includes file.
11571158 require_once TWO_FACTOR_DIR . 'includes/function.login-header.php ' ;
@@ -1643,7 +1644,7 @@ public static function _login_form_validate_2fa( $user, $nonce = '', $provider =
16431644 if ( is_wp_error ( $ provider ) ) {
16441645 // The user's configured methods don't exist, and there was no replacement to swap in. This is the
16451646 // user's own login attempt, so it's appropriate to stop here with a specific, actionable message.
1646- wp_die ( $ provider );
1647+ wp_die ( esc_html ( $ provider-> get_error_message () ) );
16471648 }
16481649 if ( ! $ provider ) {
16491650 wp_die ( esc_html__ ( 'Two-factor provider not available for this user. ' , 'two-factor ' ) );
@@ -1789,7 +1790,7 @@ public static function _login_form_revalidate_2fa( $nonce = '', $provider = '',
17891790 if ( is_wp_error ( $ provider ) ) {
17901791 // The user's configured methods don't exist, and there was no replacement to swap in. This is the
17911792 // user's own session revalidation, so it's appropriate to stop here with a specific, actionable message.
1792- wp_die ( $ provider );
1793+ wp_die ( esc_html ( $ provider-> get_error_message () ) );
17931794 }
17941795 if ( ! $ provider ) {
17951796 wp_die ( esc_html__ ( 'Two-factor provider not available for this user. ' , 'two-factor ' ) );
0 commit comments