• Resolved maxwelton

    (@maxwelton)


    If you have a custom login page, defined by filtering the login url, just as your plugin does:

    add_filter( 'login_url', 'my_login_page', 10, 1 );
    function my_login_page( $login_url ) {
        return home_url( '/login/' );
    }

    Your plugin will send the site into an infinite loop as unless a site specifically uses wp-login.php there seems to be no loop checking on auth_redirect() (which seems like a WP core bug to me, honestly).

    In any case, your plugin can be made slightly less elegant but usable in these cases by adding a conditional around your logic statement. The function would also need to pass in the $query var (available as it’s using parse_request as the action):

    function dmk_redirect_to_login_if_not_logged_in( $query ) {
        if ( home_url( '/' . $query->request . '/' ) != wp_login_url() ) {
            is_user_logged_in() || auth_redirect();
        }
    }

    https://www.ads-software.com/plugins/redirect-to-login-if-not-logged-in/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Daan Kortenbach

    (@daankortenbach)

    That is kinda weird because wp_login_url() is called right before the redirect in auth_redirect(). wp_login_url() on it’s turn applies the login_url filter right before returning the login url.

    From the auth_redirect function:

    $login_url = wp_login_url($redirect, true);
    wp_redirect($login_url);

    From the wp_login_url function:

    return apply_filters( 'login_url', $login_url, $redirect, $force_reauth );

    Could you try testing different priority levels in your add_filter and make sure there are no other filters on login_url by disabling all other plugins?

    Plugin Author Daan Kortenbach

    (@daankortenbach)

    Closing due to no reply.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect loop with custom login page’ is closed to new replies.