Skip to content

Instantly share code, notes, and snippets.

Last active December 10, 2021 15:29
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
* 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(
// ALWAYS return $roles.
return $roles;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment