From 25be2d61d75a00c2527de476d6269d7618e77b86 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Mon, 14 Feb 2022 17:38:18 +0200 Subject: [PATCH 1/2] Allow enforcing 2fa for super adminns --- class.two-factor-force.php | 10 ++++++++-- tests/class.two-factor-force.php | 23 ++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/class.two-factor-force.php b/class.two-factor-force.php index 88f59ed3..73eb7be6 100644 --- a/class.two-factor-force.php +++ b/class.two-factor-force.php @@ -280,7 +280,12 @@ public static function is_two_factor_forced( $user_id ) { // Check whether a user is in a user role that requires two-factor authentication. $two_factor_forced_roles = self::get_forced_user_roles(); - $required_roles = array_filter( $user->roles, function( $role ) use ( $two_factor_forced_roles ) { + $user_roles = $user->roles; + if ( is_super_admin( $user->ID ) ) { + array_push( $user_roles, 'super-admin' ); + } + + $required_roles = array_filter( $user_roles, function( $role ) use ( $two_factor_forced_roles ) { return in_array( $role, $two_factor_forced_roles, true ); }, ARRAY_FILTER_USE_BOTH ); @@ -373,12 +378,13 @@ public static function global_force_2fa_field() { public static function global_force_2fa_by_role_field() { $forced_roles = self::get_forced_user_roles(); $is_universally_forced = self::get_universally_forced_option(); + $roles = array_merge( [ 'super-admin' => [ 'name' => 'Super Administrator' ] ], get_editable_roles() ); ?> $role ) : + foreach ( $roles as $slug => $role ) : ?>