diff --git a/class-two-factor-core.php b/class-two-factor-core.php
index 61179cd9..b396c60a 100644
--- a/class-two-factor-core.php
+++ b/class-two-factor-core.php
@@ -571,6 +571,25 @@ public static function get_provider_for_user( $user = null, $preferred_provider
return self::get_primary_provider_for_user( $user );
}
+ /**
+ * Get the name of the primary provider selected by the user
+ * and enabled for the user.
+ *
+ * @param WP_User|int $user User ID or instance.
+ *
+ * @return string|null
+ */
+ private static function get_primary_provider_key_selected_for_user( $user ) {
+ $primary_provider = get_user_meta( $user->ID, self::PROVIDER_USER_META_KEY, true );
+ $available_providers = self::get_available_providers_for_user( $user );
+
+ if ( ! empty( $primary_provider ) && ! empty( $available_providers[ $primary_provider ] ) ) {
+ return $primary_provider;
+ }
+
+ return null;
+ }
+
/**
* Gets the Two-Factor Auth provider for the specified|current user.
*
@@ -594,7 +613,7 @@ public static function get_primary_provider_for_user( $user = null ) {
} elseif ( 1 === count( $available_providers ) ) {
$provider = key( $available_providers );
} else {
- $provider = get_user_meta( $user->ID, self::PROVIDER_USER_META_KEY, true );
+ $provider = self::get_primary_provider_key_selected_for_user( $user );
// If the provider specified isn't enabled, just grab the first one that is.
if ( ! isset( $available_providers[ $provider ] ) ) {
@@ -1788,12 +1807,7 @@ public static function user_two_factor_options( $user ) {
wp_enqueue_style( 'user-edit-2fa', plugins_url( 'user-edit.css', __FILE__ ), array(), TWO_FACTOR_VERSION );
$enabled_providers = array_keys( self::get_available_providers_for_user( $user ) );
- $primary_provider = self::get_primary_provider_for_user( $user->ID );
-
- $primary_provider_key = null;
- if ( ! empty( $primary_provider ) && is_object( $primary_provider ) ) {
- $primary_provider_key = $primary_provider->get_key();
- }
+ $primary_provider_key = self::get_primary_provider_key_selected_for_user( $user );
// This is specific to the current session, not the displayed user.
$show_2fa_options = self::current_user_can_update_two_factor_options();
@@ -1822,6 +1836,7 @@ public static function user_two_factor_options( $user ) {
}
?>
+
$notice ) : ?>
@@ -1832,21 +1847,17 @@ public static function user_two_factor_options( $user ) {
-
-
-
- |
- |
- |
-
-
+
+
+
+
assertStringContainsString( 'Authenticator app', $this->provider->get_label() );
+ $this->assertStringContainsString( 'Authenticator App', $this->provider->get_label() );
}
/**
diff --git a/user-edit.css b/user-edit.css
index a630f0e1..4280ce99 100644
--- a/user-edit.css
+++ b/user-edit.css
@@ -1,16 +1,3 @@
-.two-factor-methods-table .col-primary,
-.two-factor-methods-table .col-enabled {
- width: 5%;
-}
-
-.two-factor-methods-table .col-name {
- width: 90%;
-}
-
-.two-factor-methods-table tbody th {
- text-align: center;
-}
-
.two-factor-methods-table tbody th,
.two-factor-methods-table tbody td {
vertical-align: top;