WordPress的,直接将用户重定向到一个自定义后编辑屏幕登录
问题描述:
目前我得到了这个之后:WordPress的,直接将用户重定向到一个自定义后编辑屏幕登录
function redirect_companies()
{
if (current_user_can('ca_company'))
{
$screen = get_current_screen();
if ($screen->post_type != 'unternehmen' && $screen->id != 'profile')
{
global $current_user;
$current_users_posts = get_posts(
array(
'post_type' => 'unternehmen',
'author' => $current_user->ID
)
);
if (count($current_users_posts) > 1)
{
$redirect = admin_url('edit.php?post_type=unternehmen');
}
else
{
$redirect = get_edit_post_link($current_users_posts[0]->ID);
}
wp_redirect($redirect, 301);
}
}
}
add_action('current_screen', 'redirect_companies');
它应该做的:具有角色“ca_company”登录到WordPress后台,并立即被重定向到一个用户要么是“unternehmen”的自定义帖子类型帖子的概览屏幕,要么只有该用户的一个帖子存在,才显示到该帖子的编辑屏幕。
此外,如果用户试图访问任何不是来自帖子类型“unternehmen”而且不是用户配置文件编辑屏幕的页面,它应该执行此重定向例程。
当我已经以auch用户身份登录并尝试访问仪表板时,我成功地测试了这一点。这工作。
但是,如果我完全退出WP,然后再次登录,WordPress是执行此:
http://i.stack.imgur.com/M60aJ.png
...然后我的浏览器告诉我,有一个重定向错误。无限重定向循环。但为什么?为什么它会进入那个“如果”我检查邮政类型“unternehmen”。因为如果我登录,我先取到仪表板...
希望有人能帮助:)
答
使用这个动作 'ADD_ACTION(' wp_login', 'do_anything');”。在回调函数中,您可以链接到wp_redirect('link'),您想要重定向您的屏幕。