Last active
December 10, 2021 15:29
-
-
Save paulgoodchild/c39c1ee72bfdcdbd705362cdcc140757 to your computer and use it in GitHub Desktop.
Add custom user roles to enforce 2FA by email using Shield Security plugin for WordPress
This file contains hidden or 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 | |
/** | |
* Adding custom roles is a case of using the filter provided, adding your | |
* roles to the array of roles that has 2FA by email forced upon them. | |
* | |
* The role you add will be the 'slug' of the role, not the name of the role. | |
* For example, WordPress comes with built-in roles such as Administrator. | |
* The slug for this role is 'administrator', not 'Administrator'. | |
*/ | |
add_filter( 'odp-shield-2fa_email_user_roles', function ( $roles ) { | |
/** | |
* The role you add is the 'slug' for the role, not its pretty name. | |
*/ | |
$roles[] = 'my-custom-role'; | |
// To add multiple roles you can either: | |
// 1. add each role individually | |
$roles[] = 'my-custom-role-1'; | |
$roles[] = 'my-custom-role-2'; | |
$roles[] = 'my-custom-role-3'; | |
// 2. Or merge 2 arrays (this is probably the neater method) | |
$roles = array_merge( | |
$roles, | |
[ | |
'my-custom-role-1', | |
'my-custom-role-2', | |
'my-custom-role-3', | |
] | |
); | |
// ALWAYS return $roles. | |
return $roles; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment