Skip to content

Commit 9ad6dd6

Browse files
Handle the WP_Error fail cases
1 parent bd676f9 commit 9ad6dd6

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎class-two-factor-core.php‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ public static function get_provider_for_user( $user = null, $preferred_provider
502502

503503
if ( is_string( $preferred_provider ) ) {
504504
$providers = self::get_available_providers_for_user( $user );
505-
if ( isset( $providers[ $preferred_provider ] ) ) {
505+
if ( ! is_wp_error( $providers ) && isset( $providers[ $preferred_provider ] ) ) {
506506
return $providers[ $preferred_provider ];
507507
}
508508
}
@@ -530,6 +530,9 @@ public static function get_primary_provider_for_user( $user = null ) {
530530
// If there's only one available provider, force that to be the primary.
531531
if ( empty( $available_providers ) ) {
532532
return null;
533+
} elseif ( is_wp_error( $available_providers ) ) {
534+
// If it returned an error, the configured methods don't exist, and it couldn't swap in a replacement.
535+
wp_die( $available_providers );
533536
} elseif ( 1 === count( $available_providers ) ) {
534537
$provider = key( $available_providers );
535538
} else {
@@ -808,6 +811,11 @@ public static function login_html( $user, $login_nonce, $redirect_to, $error_msg
808811

809812
$rememberme = intval( self::rememberme() );
810813

814+
if ( is_wp_error( $available_providers ) ) {
815+
// If it returned an error, the configured methods don't exist, and it couldn't swap in a replacement.
816+
wp_die( $available_providers );
817+
}
818+
811819
if ( ! function_exists( 'login_header' ) ) {
812820
// We really should migrate login_header() out of `wp-login.php` so it can be called from an includes file.
813821
include_once TWO_FACTOR_DIR . 'includes/function.login-header.php';
@@ -1721,7 +1729,14 @@ public static function manage_users_custom_column( $output, $column_name, $user_
17211729
public static function user_two_factor_options( $user ) {
17221730
wp_enqueue_style( 'user-edit-2fa', plugins_url( 'user-edit.css', __FILE__ ), array(), TWO_FACTOR_VERSION );
17231731

1724-
$enabled_providers = array_keys( self::get_available_providers_for_user( $user ) );
1732+
$available_providers = self::get_available_providers_for_user( $user );
1733+
1734+
if ( is_wp_error( $available_providers ) ) {
1735+
// If it returned an error, the configured methods don't exist, and it couldn't swap in a replacement.
1736+
wp_die( $available_providers );
1737+
}
1738+
1739+
$enabled_providers = array_keys( $available_providers );
17251740
$primary_provider = self::get_primary_provider_for_user( $user->ID );
17261741

17271742
if ( ! empty( $primary_provider ) && is_object( $primary_provider ) ) {

0 commit comments

Comments
 (0)