Redirect loop with custom login page
-
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)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Redirect loop with custom login page’ is closed to new replies.