I'm looking for a way to avid that some custom users roles are able to see wp-admin dashboard. I've found this topic and in my plugin class I've tried to use the two action suggested, but I will get an error about too few arguments passed.
This is my implementation of the code
public function hide_dashboard_from_users( $user_login, $user )
{
if( !current_user_can('manage_options') && is_array($user->roles) && in_array('customer', $user->roles) ){
wp_safe_redirect( site_url('/user-profile') );
}elseif( !current_user_can('manage_options') && is_array($user->roles) && in_array('operator', $user->roles) ){
wp_safe_redirect( site_url('/customers-manager') );
}
}
into the class construct I have these two actions
add_action('wp_login', array($this, 'hide_dashboard_from_users'), 10, 2);
add_action('admin_init', array($this, 'hide_dashboard_from_users'));
Why I will get the error and how I can fix it? Is there other actions or filter I can use to achive this?