Skip to content

teacher_login_redirect exits before Two Factor shows the code screen #8470

Open

Description

@MxchaelA8C

Steps to Reproduce

  1. Install the Two Factor plugin (https://wordpress.org/plugins/two-factor/) and turn on 2FA for a user who can edit courses (edit_courses).
  2. Log in as that user [from the My Courses page / from wp-login.php].
  3. 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.

Sensei: https://github.com/Automattic/sensei/blob/version/4.27.0/includes/class-sensei-teacher.php
Two Factor: https://github.com/WordPress/two-factor/blob/master/class-two-factor-core.php

PHP / WordPress / Sensei LMS version

PHP: 8.4.28
WordPress: 7.1.5
Sensei Pro: 4.27.0.1.24.11
Two Factor: 0.17.0

Browser / OS version

Chrome (incognito) and Safari.

Context / Source

Reported on a WordPress VIP site. #ZD-237238

Activity

  1. jinnypark commented on Nov 20, 2026

    @jinnypark
    Member

    ✅ 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).

    1. 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.
    2. Same login with wp-login.php as the referrer: the Two Factor code screen shows.
    3. 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.

    Triage assisted by Claude.

  2. added
    [Status] Triaged
    [Pri] Normal
    and removed
    [Status] Needs Triage
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Pri] Normal[Status] Triaged[Type] Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions