Look through TML’s files to see how it handles determining the user’s role to get an idea how to accomplish this.
Can you please explain? I’ve just spent over 3 hours trying to figure this out but couldn’t find where / what code to do this… Any guidance would be more than appreciated!
Thanks
function tml_redirect_login_by_role() {
if ( Theme_My_Login::is_tml_page( 'login' ) && is_user_logged_in() ) {
$user = wp_get_current_user();
$user_role = reset( $user->roles );
switch ( $user_role ) {
case 'administrator' :
$redirect_to = 'SOME URL';
break;
case 'editor' :
$redirect_to = 'SOME URL';
break;
default :
// Catch all
$redirect_to = 'SOME URL';
}
wp_redirect( $redirect_to );
exit;
}
}
add_action( 'template_redirect', 'tml_redirect_login_by_role' );
Jeff,
Instead of the solution you offered above, I’d like logged in users to go to the page set in the “Redirection” field within the plugin (under Log In) whenever they try to go to the login page.
What’s the best way to do this?
Thanks
function tml_redirect_logged_in() {
if ( Theme_My_Login::is_tml_page( 'login' ) && is_user_logged_in() ) {
$redirect_to = apply_filters( 'login_redirect', admin_url( 'profile.php' ), '', wp_get_current_user() );
wp_redirect( $redirect_to );
exit;
}
}
add_action( 'template_redirect', 'tml_redirect_logged_in' );
I added your code to the themes function.php but it didn’t work. It still keeps redirecting to profile page for all user types…
Try making it a higher priority:
add_action( 'template_redirect', 'tml_redirect_logged_in', 8 );