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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745627781a4636914.html
评论列表(0条)