Created
November 15, 2022 16:02
-
-
Save mustardBees/9b9b840dfc778d031a778f91c1422f67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Enable email-based 2FA by default. | |
* | |
* @author pjv | |
* @link https://link.from.pw/3P7cH9u | |
* | |
* @param $providers | |
* @param $user_id | |
* @return mixed | |
*/ | |
function pw_default_2fa( $providers, $user_id ) { | |
$force_roles = array( | |
'administrator', | |
'editor', | |
); | |
$user = get_user_by( 'id', $user_id ); | |
if ( empty( array_intersect( $force_roles, $user->roles ) ) ) { | |
return $providers; | |
} | |
if ( empty( $providers ) && class_exists( 'Two_Factor_Email' ) ) { | |
$providers[] = 'Two_Factor_Email'; | |
} | |
return $providers; | |
} | |
add_filter( 'two_factor_enabled_providers_for_user', 'pw_default_2fa', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment