I have insert the login form on the header part and when a user is logedin i need to redirect them based on their role to their profile page(like if they are normal than normal-member.php and if pro user than pro-user.php). How can i do that using the wp_login_form.Any suggestion please...
I have insert the login form on the header part and when a user is logedin i need to redirect them based on their role to their profile page(like if they are normal than normal-member.php and if pro user than pro-user.php). How can i do that using the wp_login_form.Any suggestion please...
Share Improve this question asked Sep 5, 2015 at 18:04 clapclap 391 silver badge7 bronze badges1 Answer
Reset to default 1You can use the login_redirect filter for this purpose:
/**
* 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( $redirect_to, $request, $user ) {
//is there a user to check?
global $user;
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
//here make if statements for your specific roles and locations
} else {
return home_url();
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745078264a4609964.html
评论列表(0条)