我有一个功能哪种作品。第一次清除Cookie时,它将不起作用。但下次登录后,我将被重定向。为什么会这样?
function role_user_redirect_login($username, $user){
if(array_key_exists(\'user\', $user->caps)){
wp_redirect(admin_url(\'edit.php?post_type=test\', \'https\'), 301);
exit;
}
}
add_action(\'wp_login\', \'role_user_redirect_login\', 10, 2);
SO网友:ahendwh2
您应该使用过滤器login_redirect 而不是wp_login:
function role_user_redirect_login($redirect_to, $request, $user){
if(array_key_exists(\'user\', $user->caps)){
return admin_url(\'edit.php?post_type=test\', \'https\');
}
return $redirect_to;
}
add_filter(\'login_redirect\', \'role_user_redirect_login\', 10, 3);