Add email verification before activation#788
Add email verification before activation#788faisalahammad wants to merge 2 commits intoWordPress:masterfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
georgestephanis
left a comment
There was a problem hiding this comment.
I want to see this go in, but I think to avoid merge conflicts it'll need to pause until #814 goes in, or that will need to pause for this. Or this can just start doing the newer external include. Either way.
Like the idea, but there's some extra changes in the PR that I don't think need to be in this PR? I'm looking at the distignore, and I'm not sure why it's changing from protected to public for the constructor ... possibly totally reasonable, I'm just trying to be thorough.
There was a problem hiding this comment.
Pull request overview
Adds an email-verification step for the Email two-factor provider by introducing a “verified” user-meta flag, a REST-driven verification flow in the profile UI, and guardrails to prevent enabling Email 2FA unless verified (with legacy compatibility).
Changes:
- Add
VERIFIED_META_KEYand gateis_available_for_user()on verification (while allowing legacy-enabled users). - Introduce Email provider REST endpoints to send/verify codes and to deactivate/reset verification state.
- Expand unit tests for email contents, availability gating, and profile-save behavior; update
.distignore.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
providers/class-two-factor-email.php |
Adds verification meta key, REST endpoints, updated email content handling, UI changes, and profile-save enforcement. |
tests/providers/class-two-factor-email.php |
Adds/updates tests for verification-context emails, availability rules, and pre_user_options_update() behavior. |
.distignore |
Ignores two-factor.zip from distribution exports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
masteradhoc
left a comment
There was a problem hiding this comment.
Hey @faisalahammad
Thanks for your PR :) as we've just merged #814 would you mind seperating your code as well to the seperate files that the PR added?
abc10ef to
2515e10
Compare
|
I have updated the PR to address all the feedback:
Ready for another review! |
|
@faisalahammad could you please:
this would make it a lot easier to review the PR properly :) |
4bab1d9 to
412d2fe
Compare
|
Hi @masteradhoc, I’ve updated the branch based on your feedback:
Could you please check and let me know if everything good to merge?
|
Implements a verification step for the Email provider. Users must verify their email address before the Email 2FA method can be enabled. Legacy users who already have Email 2FA enabled are unaffected. Changes: - Add REST API endpoints for email verification (POST/DELETE /two-factor/1.0/email) - Add VERIFIED_META_KEY to track verified email addresses - Update is_available_for_user() to require verification (with legacy fallback) - Add pre_user_options_update() to prevent enabling without verification - Add email-admin.js for verification UI interactions - Add is_wp_error() guards for get_available_providers_for_user() calls - Add comprehensive REST API and unit tests Fixes WordPress#778
412d2fe to
a0f6973
Compare
|
Hi @masteradhoc, Thanks for the feedback! I've updated the PR with the following changes:
Everything should be green now. Could you please re-review when you have a chance? |
masteradhoc
left a comment
There was a problem hiding this comment.
early feedback. @nimesh-xecurify could you check the tests added in this PR if they are fine?
providers/class-two-factor-email.php
Outdated
| /** | ||
| * Enqueue scripts for email provider. | ||
| * | ||
| * @since 0.10.0 |
There was a problem hiding this comment.
| * @since 0.10.0 | |
| * @since 0.16.0 |
as this is a new function, use proper version number
if we can get this ready it will be in 0.16.0 else in 0.17.0
- Fix enqueue_assets() @SInCE version: 0.10.0 → 0.16.0 - Add missing @SInCE 0.16.0 to register_rest_routes() - Add missing @SInCE 0.16.0 to rest_setup_email() - Add missing @SInCE 0.16.0 to rest_delete_email() - Add missing @SInCE 0.16.0 to pre_user_options_update() - Fix test_user_two_factor_rest_setup_email_valid_code: replace undefined is_provider_enabled_for_user() with in_array check - Fix test_user_can_delete_email_verification: set verified meta before enabling provider - Fix test_admin_can_delete_email_for_others: add enable_provider_for_user call - Fix test_generate_and_email_token_login_context_correct_args: match assertions to actual email body text - Fix test_other_sessions_destroyed_when_enabling_2fa: add verified meta before enabling Email 2FA - Fix test_user_options (backup codes): update assertion for wp_scripts data
|
Hi @masteradhoc, Thanks for the thorough review! I've pushed a fix addressing all your feedback: @ since tag fixes:
CI test failures fixed:
Could you please re-review when you get a chance? |

Description
This PR implements a verification step for the Email provider in the Two-Factor plugin.
Previously, users could enable Email 2FA without confirming ownership of the email address, which posed a risk of account lockout if the email was incorrect or inaccessible. This change aligns the Email provider's activation flow with the TOTP provider by requiring successful code verification before the provider can be enabled.
Changes
POST /two-factor/1.0/email: Handles sending verification codes and validating them.DELETE /two-factor/1.0/email: Handles resetting the verification status (if needed).Two_Factor_Email::is_available_for_user()now returnstrueonly if the user has verified their email (checked via_two_factor_email_verifieduser meta).pre_user_options_updatehook to prevent the Email provider from being enabled via the standard profile form save unless the user is verified.How to Test
New User (Fresh Setup)
Legacy User (Existing Setup)
Screenshot
Technical Details
Two_Factor_Emailregister_rest_routes()rest_setup_email()rest_delete_email()pre_user_options_update()user_options(): updated to render the verification UI.is_available_for_user(): added verification check (with legacy fallback).generate_and_email_token(): updated to accept an$actionargument ('login' vs 'verification_setup') to send context-appropriate emails.VERIFIED_META_KEY:_two_factor_email_verifiedChecklist
Fixes #778