the issue was…
myappname_login_redirect
needs to return $redirect_to
in any case
otherwise the redirect to gets lost
background:
wp-login.php will render the redirect_to value into an input hidden into the login form.
so arriving at
wp-login.php?redirect_to=www.example.com
will render
an
<input type="hidden" value="www.example.com">
this value will be empty, if the filter does not return it by default
so fix…
function myappname_login_redirect($redirect_to, $request, $user)
{
if ($user instanceof WP_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 $redirect_to;
} else {
//if something is set her for exceptions, we allow regular redirect as well
if($_GET['myappname_allow_redirect']){
return $redirect_to;
}else{
//but normally we redirect to a standard url
return 'somethingelse';
}
}
} else {
return $redirect_to;
}
}
//is there a user to check?
return $redirect_to;
}
add_filter('login_redirect', 'myappname_login_redirect', 10, 3);