Logged in User Redirect to Custom Redirect URL
-
Hello. Hoping someone can help. I am trying to tweak this function provided in the docs that redirect a user on the login screen AFTER they are logged in so it behaves exactly the same way when they login for the first time.
In the settings under User Roles there is a setting : Set Custom Redirect URL which you can specify for each User Role. So when that user logs in, they get redirected to a specific url. This works great. The issue is if a user is already logged in and then comes back to the login screen, they aren’t redirected.
I believe that is getting defined in the plugin as “_um_login_redirect_url”.
So if we’re using this function, I need wp_redirect() to redirect to the users _um_login_redirect_url of their user role. In this way, if they are logged in and go back to /login, we just redirect them back to their custom url as defined to their user role.
But having trouble with the syntax to set the _um_login_redirect_url value to a variable so i can drop it into the wp_redirect()
So need to replace this:
add_action( ‘template_redirect’, ‘um_restrict_login_page_logged_in’ );
function um_restrict_login_page_logged_in() {
if ( um_is_core_page(‘login’) && is_user_logged_in() ) {
wp_redirect( um_get_core_page( ‘user’ ) );
exit;
}
}with something like this but not sure how to get the _um_login_redirect_url defined correctly.
add_action( ‘template_redirect’, ‘um_restrict_login_page_logged_in’ );
function um_restrict_login_page_logged_in() {
if ( um_is_core_page(‘login’) && is_user_logged_in() ) {
$redirect = $role[‘_um_login_redirect_url’];
wp_redirect( $redirect );
exit;
}
}The page I need help with: [log in to see the link]
- The topic ‘Logged in User Redirect to Custom Redirect URL’ is closed to new replies.