Login Module Ignores Redirect Rules
-
On a staging site I’m working on, I’m having an issue with your plugin’s login module.
I have a custom function that has worked well for me for years. It directs admins, authors, and editors to /wp-admin/ and it directs everyone else to /my-account/ for their front-end account dashboard.
The login module seems to be ignoring this function though.
I’ve tried it with redirection set, and not set, in the module settings.
In all cases, when I log in using any account level, the login page just seems to reload with a message saying I’m logged in successfully.
Here’s the code we’ve used for quite some time with other login forms. It’s adapted from the example in the WP help documentation. Code’s below:
/** * Redirect user after successful login. * * @param string $redirect_to URL to redirect to. * @param string $request URL the user is coming from. * @param object $user Logged user's data. * @return string */ function my_login_redirect( $url, $request, $user ){ if( !defined( 'DOING_AJAX' ) && $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) { if( $user->has_cap( 'administrator') or $user->has_cap( 'publish_posts')) { $url = admin_url(); } else { $url = home_url('/my-account/'); } } return $url; } add_filter('login_redirect', 'my_login_redirect', 10, 3 );
When I test on the old login page (using Divi’s login module rather than this one), the redirects still work fine, so I don’t think it’s an issue of this being a private test site. I’m only seeing the issue when using the new login form through the Elementor add-ons.
Any help getting this to work again would be appreciated. Thanks!
- The topic ‘Login Module Ignores Redirect Rules’ is closed to new replies.