#906: add early notice for soon exhausting recovery codes#907
Open
masteradhoc wants to merge 1 commit into
Open
#906: add early notice for soon exhausting recovery codes#907masteradhoc wants to merge 1 commit into
masteradhoc wants to merge 1 commit into
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. |
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?
Adds a proactive "running low on Recovery Codes" admin notice that appears before a user exhausts their codes, rather than only warning them once they are completely out. While more than the threshold of codes remain, nothing shows; at or below the threshold (default 2) a dismissible-styled warning appears; at zero the existing error notice still shows.
Fixes #906
Why?
Today
Two_Factor_Backup_Codes::admin_notices()only surfaces a notice after the user has used their last Recovery Code (balance = 0). By then the user has already lost their self-service path back into the account. There is no earlier nudge to regenerate, so it is easy to drift down to zero unnoticed and get locked out.This closes gap #5 in the account-recovery roadmap (
account-recovery-future-improvements.md) and is the low-balance-warning half of item C / Phase 1 in that document. It strengthens the one self-service recovery path users already have, without adding any new bypass or attack surface.Related discussion:
How?
admin_notices()was restructured from a single zero-codes check into three states, keyed oncodes_remaining_for_user():notice notice-warningerrorLOW_CODES_THRESHOLDconstant (default2) sets the warning point.two_factor_backup_codes_low_thresholdfilter lets operators tune it per-site (receives the count and theWP_User). The name follows the existing internaltwo_factor_backup_code_lengthconvention._n()for singular/plural ("1 recovery code" vs "2 recovery codes"), with the count run throughnumber_format_i18n()./wp-admin/profile.php#two-factor-backup-codes, matching the existing notice.Behaviour by state:
More than two Recovery Codes left — no notice.
Two Recovery Codes left
Link goes to
/wp-admin/profile.php#two-factor-backup-codes.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Drafting the issue/PR text and the initial implementation of the low-balance notice. Final implementation and wording were reviewed and edited by me.
Testing Instructions
profile.php#two-factor-backup-codes.add_filter( 'two_factor_backup_codes_low_threshold', fn() => 5 );and confirm the warning now triggers at 5 or fewer codes.Changelog Entry