Created
July 7, 2016 16:14
-
-
Save alokstha1/965fbd12cc6ae411805efeba7024e61b to your computer and use it in GitHub Desktop.
Add Parameter to url on unsuccessful login attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_login_failed', 'code_login_failed' ); | |
function code_login_failed( $user ) { | |
// check what page the login attempt is coming from | |
$referrer = $_SERVER['HTTP_REFERER']; | |
// check that were not on the default login page | |
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') && $user!=null ) { | |
// make sure we don't already have a failed login attempt | |
if ( !strstr($referrer, '?login=failed' )) { | |
// Redirect to the login page and append a querystring of login failed | |
$new_redirect = add_query_arg( 'login', 'failed', $referrer ); | |
wp_redirect( $new_redirect ); | |
} else { | |
wp_redirect( $referrer ); | |
} | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment