Fix TOTP verify button after resetting authenticator app - #979
Fix TOTP verify button after resetting authenticator app#979lakrisgubben wants to merge 2 commits into
Conversation
Clicking "Reset authenticator app" replaces the contents of #two-factor-totp-options via AJAX, but the click handlers for .totp-submit and .button.reset-totp-key were bound directly to elements present at page load. The new "Verify" button never got those handlers, so clicking it fell back to a native form submit instead of the AJAX request, triggering the browser's unsaved changes prompt. Delegate both handlers off the persistent #two-factor-totp-options container so they keep working after its contents are replaced. Fixes WordPress#978
|
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. |
There was a problem hiding this comment.
🟢 Approval recommended
The change directly addresses the reported issue by delegating the event handlers to a persistent container without introducing behavioral regressions in the reviewed code.
Pull request overview
This PR fixes the TOTP “Verify” button behavior on the user profile screen after “Reset authenticator app” replaces the TOTP options markup via AJAX. It updates the admin JS to use delegated event handlers so the click logic continues to work for dynamically replaced buttons.
Changes:
- Switched the TOTP “Verify” click handler to delegated binding on
#two-factor-totp-options. - Switched the “Reset authenticator app” click handler to delegated binding on
#two-factor-totp-options.
File summaries
| File | Description |
|---|---|
| providers/js/totp-admin.js | Uses delegated click handlers so “Verify” and “Reset authenticator app” continue to work after the options area is re-rendered via AJAX. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
masteradhoc
left a comment
There was a problem hiding this comment.
Thank you for this PR @lakrisgubben!
I've just validated the fix locally and on WP Playground and it fixes the noted issue perfectly.
|
@georgestephanis this small bugfix fine for you as well? then it would be ready to merge |
What?
Clicking "Reset authenticator app" replaces the contents of #two-factor-totp-options via AJAX, but the click handlers for .totp-submit and .button.reset-totp-key were bound directly to elements present at page load. The new "Verify" button never got those handlers, so clicking it fell back to a native form submit instead of the AJAX request, triggering the browser's unsaved changes prompt.
Fixes #978
Why?
Making sure users can easily switch authenticator app.
How?
Delegate both handlers off the persistent #two-factor-totp-options container so they keep working after its contents are replaced.
Use of AI Tools
AI assistance: Yes
Tool: Claude code
Model: Sonnet 5
Used for: Initial finding of what code triggered the bug, wording on issue.
Testing Instructions
Before this PR it wouldn't work, with this PR it works.
Changelog Entry
Fixed – Clicking TOTP verify button after resetting authenticator app