I have chosen to display a login form in the first page of my wordpress website. If the user logs in successfully, he gets redirected to a specific webpage. If he enters a wrong password, he gets redirected to the login page again. The problem happens when someone does not enter username and password: he gets redirected to the wordpress admin login page.
How can I redirect empty username logins back to the main login page ?
this is the code I am using to redirect failed attempts :
add_filter('login_redirect', '_catch_login_error', 10, 3);
function _catch_login_error($redir1, $redir2, $wperr_user)
{
if(!is_wp_error($wperr_user) || !$wperr_user->get_error_code()) return $redir1;
switch($wperr_user->get_error_code())
{
case 'incorrect_password':
case 'empty_password':
case 'invalid_username':
default:
wp_redirect(home_url()); // modify this as you wish
}
return $redir1;
}
Check for an empty user login in the
$_REQUEST
array:But this filter is to late. It is called after the user is logged in. You have to use the
'wp_authenticate'
action, this is one of the earliest action in the login process: