Is your enhancement related to a problem? Please describe.
Currently, Two_Factor_Backup_Codes::admin_notices() only surfaces a notice after a user has consumed every last recovery code (balance = 0). By that point the user has no self-service path left. This issue adds a second, earlier notice that fires while the user still has a small number of codes remaining — giving them enough time to regenerate before they are locked out.
This closes a gap from the recovery-improvements plan.
Current behaviour
admin_notices() in providers/class-two-factor-backup-codes.php returns early unless is_available_for_user() is false, meaning it only fires when the code count reaches zero:
// Return if we are not out of codes.
if ( $this->is_available_for_user( $user ) ) {
return;
}
The profile UI already displays the live code count (via user_options()), but no proactive nudge appears in wp-admin to prompt regeneration before the user is completely out.
Proposed changes
- Introduce a low-balance threshold constant and filter
- Extend
admin_notices() with two distinct notice levels
- No changes to non-admin surfaces
Acceptance criteria
Please confirm that you have searched existing issues in this repository.
Yes
Is your enhancement related to a problem? Please describe.
Currently,
Two_Factor_Backup_Codes::admin_notices()only surfaces a notice after a user has consumed every last recovery code (balance = 0). By that point the user has no self-service path left. This issue adds a second, earlier notice that fires while the user still has a small number of codes remaining — giving them enough time to regenerate before they are locked out.This closes a gap from the recovery-improvements plan.
Current behaviour
admin_notices()inproviders/class-two-factor-backup-codes.phpreturns early unlessis_available_for_user()isfalse, meaning it only fires when the code count reaches zero:The profile UI already displays the live code count (via
user_options()), but no proactive nudge appears in wp-admin to prompt regeneration before the user is completely out.Proposed changes
admin_notices()with two distinct notice levelsAcceptance criteria
two_factor_backup_codes_low_thresholdcodes (default: 2).warning-class notice appears in wp-admin when codes remaining is between 1 and the threshold (inclusive), containing the remaining count and a link to the profile regeneration anchor.error-class notice still appears when codes reach 0.two_factor_backup_codes_low_thresholdfilter.Please confirm that you have searched existing issues in this repository.
Yes