I developed a plugin for wordpress and I want to redirect different roles to different pages after login. I use below code and it works on my localhost (I use xamp) , but when I upload my plugin to server it doesn't work! and it just remain in "wp-login.php"
after logining in and ofcourse the page goes white.
Code:
function loginRedirect( $redirect_to, $request, $user ){
global $user;
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) )
{
// redirect them to the default place
return home_url()."/wp-admin/";
} else if ( in_array( 'manager', $user->roles ) )
{
return home_url()."/wp-admin/admin.php?page=creat_mysite_list_entry";
}
else if ( in_array( 'jobholder', $user->roles ) )
{
if(have_contract_user($user->ID))
{
return home_url()."/wp-admin/admin.php?page=creat_mysite_register_entry";
}
else
{
return wp_logout_url();
}
}
}
}
add_filter("login_redirect", "loginRedirect", 10, 3);