简体   繁体   中英

WordPress redirect specific user after login

I am trying to redirect a specific user from the admin dashboard to the WooCommerce order page after successful login.

My code kinda seems to be working. The redirect is happening but it displays an error message "Sorry you do not have permission to view this page". I am 100% sure that the user has permission to view that particular page.

I am somewhat thinking that this is because the redirect is happening before the actual session is set. Any idea how to solve this?

My code:

function my_login_redirect($redirect_to, $request, $user){
    if($user->user_login == 'monitor') {
        return home_url("/wp-admin/edit.php?post_type=shop_order/");
    }
}
add_filter("login_redirect", "my_login_redirect", 10, 3);

If you are sure about permission, remove last slash and try again.

return home_url("/wp-admin/edit.php?post_type=shop_order");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM