admin管理员组文章数量:1435858
I have a user with custom role; but when I login as a user with custom role it redirects me to the homepage of my site. I tried using this code through my plugin but still it redirects to the homepage:
$this->loader->add_action("login_redirect", $plugin_public,"user_login_handler", 99999, 3);// User Login Handler
public function user_login_handler($redirect_to, $request, $user)
{
//$user = new WP_User($user);
//is there a user to check?
// require_once plugin_dir_path(dirname(__FILE__)) . 'admin/models/tscgd-user.php';
//check for Dashboard User
if ( ! is_wp_error( $user ) ) {
if (array_intersect($this->user_role_slug, (array) $user->roles)) {
// redirect them to another URL, in this case, the homepage
$redirect_to = get_site_url() . "/wp-admin/";
}
}
return $redirect_to;
}
I have a user with custom role; but when I login as a user with custom role it redirects me to the homepage of my site. I tried using this code through my plugin but still it redirects to the homepage:
$this->loader->add_action("login_redirect", $plugin_public,"user_login_handler", 99999, 3);// User Login Handler
public function user_login_handler($redirect_to, $request, $user)
{
//$user = new WP_User($user);
//is there a user to check?
// require_once plugin_dir_path(dirname(__FILE__)) . 'admin/models/tscgd-user.php';
//check for Dashboard User
if ( ! is_wp_error( $user ) ) {
if (array_intersect($this->user_role_slug, (array) $user->roles)) {
// redirect them to another URL, in this case, the homepage
$redirect_to = get_site_url() . "/wp-admin/";
}
}
return $redirect_to;
}
Share
Improve this question
edited Apr 4, 2019 at 20:30
butlerblog
5,1313 gold badges28 silver badges44 bronze badges
asked Apr 4, 2019 at 19:31
The DreamerThe Dreamer
112 bronze badges
1 Answer
Reset to default 1This is what I'm using, it redirects "shop_managers" to the admin orders page.
function my_login_redirect( $redirect_to, $request, $user ){
if (isset($user->roles) && is_array($user->roles)) {
if (in_array('shop_manager', $user->roles)) {
$redirect_to = '/wp-admin/edit.php?post_type=shop_order';
}
}
return $redirect_to;
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
Obviously, you will need to change 'shop_managers' and '/wp-admin/edit.php?post_type=shop_order' to what you need.
Tested and working.
本文标签: pluginsRedirecting to home page after login as custom role WordPress
版权声明:本文标题:plugins - Redirecting to home page after login as custom role WordPress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745627781a2667079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论