You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
teacher_login_redirect exits before Two Factor shows the code screen #8470
Log in as that user [from the My Courses page / from wp-login.php].
See the login loop.
What I Expected
After the password step, the Two Factor code screen shows. The redirect to wp-admin happens after the code is entered.
What Happened Instead
The user is sent from wp-login.php to wp-admin and straight back to wp-login.php?reauth=1, with no code screen and no error. The login POST returns a 303. Resetting the user's 2FA lets them log in.
Cause: Sensei's teacher_login_redirect() redirects and calls exit on wp_login. Two Factor shows its code screen from its own wp_login handler (hooked at PHP_INT_MAX), so it never runs.
When a user who can edit courses logs in from the My Courses page and has Two Factor enabled, Sensei redirects to wp-admin and stops the request before Two Factor can show its code screen. The user then lands back on wp-login.php with reauth=1. Logging in from wp-login.php directly works.
Evidence: reproduced on a local test site with Two Factor 0.17.0 and the email provider, with a teacher account.
Technical details
Environment: WP 7.1.4, Sensei 4.27.0, Two Factor 0.17.0 (email provider), user with the Teacher role (edit_courses).
Posted the login form to wp-login.php with the My Courses page as the referrer: 303 to /wp-admin/, then back to wp-login.php?redirect_to=…&reauth=1. No code screen.
Same login with wp-login.php as the referrer: the Two Factor code screen shows.
Same login as step 1 with Sensei deactivated: the Two Factor code screen shows.
teacher_login_redirect() runs on wp_login at priority 99 and calls exit after the redirect. Two Factor shows its code screen from its own wp_login handler at PHP_INT_MAX, so it never runs. The redirect only applies when the referrer is the My Courses page (since #7747's fix).
Duplicates/related:#7747 (closed, the same redirect broke other plugins' wp_login handlers; the priority was raised and the redirect limited to the My Courses page, which does not help handlers that run later).
Affected code:
includes/class-sensei-teacher.php:1733 — teacher_login_redirect() calls exit after redirecting.
includes/class-sensei-teacher.php:111 — hooked on wp_login at priority 99.
Priority (estimate, not applied):[Pri] Normal — a login loop for teachers and admins who have 2FA and sign in from the My Courses page; they can sign in from wp-login.php instead. Effort: Low — a small change in one method, plus a test. Fix: apply the My Courses redirect through the login_redirect filter instead of redirecting and exiting on wp_login, so other login handlers still run. Not tested.
Activity
jinnypark commentedon Nov 20, 2026
✅ Confirmed
When a user who can edit courses logs in from the My Courses page and has Two Factor enabled, Sensei redirects to wp-admin and stops the request before Two Factor can show its code screen. The user then lands back on wp-login.php with
reauth=1. Logging in from wp-login.php directly works.Evidence: reproduced on a local test site with Two Factor 0.17.0 and the email provider, with a teacher account.
Technical details
Environment: WP 7.1.4, Sensei 4.27.0, Two Factor 0.17.0 (email provider), user with the Teacher role (
edit_courses).wp-login.phpwith the My Courses page as the referrer:303to/wp-admin/, then back towp-login.php?redirect_to=…&reauth=1. No code screen.wp-login.phpas the referrer: the Two Factor code screen shows.teacher_login_redirect()runs onwp_loginat priority 99 and callsexitafter the redirect. Two Factor shows its code screen from its ownwp_loginhandler atPHP_INT_MAX, so it never runs. The redirect only applies when the referrer is the My Courses page (since #7747's fix).Duplicates/related: #7747 (closed, the same redirect broke other plugins'
wp_loginhandlers; the priority was raised and the redirect limited to the My Courses page, which does not help handlers that run later).Affected code:
includes/class-sensei-teacher.php:1733—teacher_login_redirect()callsexitafter redirecting.includes/class-sensei-teacher.php:111— hooked onwp_loginat priority 99.Priority (estimate, not applied):
[Pri] Normal— a login loop for teachers and admins who have 2FA and sign in from the My Courses page; they can sign in from wp-login.php instead.Effort: Low — a small change in one method, plus a test.
Fix: apply the My Courses redirect through the
login_redirectfilter instead of redirecting and exiting onwp_login, so other login handlers still run. Not tested.Triage assisted by Claude.