wp login form - How to redirect wp_login_form to new page after user loged in?

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 t

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

You 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

相关推荐

  • wp login form - How to redirect wp_login_form to new page after user loged in?

    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 t

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信