Repository navigation
Email users about low recovery codes and redirect to regenerate after the last one - #1015
Merged
Merged
Conversation
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
masteradhoc
marked this pull request as ready for review
October 2, 2026 21:03
|
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
approved these changes
Oct 22, 2026
georgestephanis
left a comment
Collaborator
There was a problem hiding this comment.
Should be fine but a couple minor things that we may want to tidy first.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Emails users when they are running low on, or have run out of, recovery codes. After a user logs in with their last code, they are sent straight to the recovery codes section of their profile.
Follow-up to #907.
Why?
#907 added admin notices that warn users when they are running low on recovery codes, and when they have none left. Those notices only appear in wp-admin. An email reaches users wherever they are. Redirecting to the recovery codes section after the last code saves them the extra step.
How?
Two_Factor_Backup_Codes::validate_code()now calls the newnotify_user_codes_running_low()after a code is used.two_factor_backup_codes_low_thresholdfilter moved into a privateget_low_codes_threshold()helper, so the notice and the email always use the same value. Name, default and arguments are unchanged.maybe_redirect_to_regenerate_codes()runs ontwo_factor_user_authenticatedandtwo_factor_user_revalidated.login_redirectfilter atPHP_INT_MAXpointing toget_edit_profile_url() . '#two-factor-backup-codes'.get_edit_profile_url()becauseget_edit_user_link()returns an empty string during login, before the current user is set.readme.txt. The threshold filter shipped in 0.17.0 but wasn't documented yet. The new tests are listed inTESTS.md.tests/providers/class-two-factor-backup-codes.php, plus an end-to-end login test intests/class-two-factor-core.php.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Implementation, tests, documentation updates and this description. I reviewed and tested the changes before opening the PR.
Testing Instructions
wp two-factor backup-codes generate <user> --count=4 --yes.add_filter( 'two_factor_backup_codes_low_threshold', '__return_zero' );to an mu-plugin and repeat. Only the "out of recovery codes" email is sent.Changelog Entry