How to add custom user role(s) to enforce 2FA by email

If you want to add custom user role(s) to enforce 2FA by email using Shield, this is how you can do that:
https://gist.github.com/paulgoodchild/c39c1ee72bfdcdbd705362cdcc140757

The most common place people put this code is in their functions.php file in their theme, but you can put it anywhere as long as it's executed early.

Please note: After using this WordPress filter the user interface selection options wont change. This programmatically updates the underlying options that are enabled, and you will see no visible indicators on the UI of this.