Created
January 18, 2016 16:07
-
-
Save digitalhydra/3b06d78ca80483841441 to your computer and use it in GitHub Desktop.
How to not redirect to wp-login.php if login fails?
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
| /*-------------------------------------------------------------------------------------*/ | |
| /* Login Hooks and Filters | |
| /*-------------------------------------------------------------------------------------*/ | |
| if( ! function_exists( 'custom_login_fail' ) ) { | |
| function custom_login_fail( $username ) { | |
| $referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from? | |
| // if there's a valid referrer, and it's not the default log-in screen | |
| if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) { | |
| if ( !strstr($referrer,'?login=failed') ) { // make sure we don’t append twice | |
| wp_redirect( $referrer . '?login=failed' ); // append some information (login=failed) to the URL for the theme to use | |
| } else { | |
| wp_redirect( $referrer ); | |
| } | |
| exit; | |
| } | |
| } | |
| } | |
| add_action( 'wp_login_failed', 'custom_login_fail' ); // hook failed login | |
| if( ! function_exists( 'custom_login_empty' ) ) { | |
| function custom_login_empty(){ | |
| $referrer = $_SERVER['HTTP_REFERER']; | |
| if ( strstr($referrer,get_home_url()) && $user==null ) { // mylogin is the name of the loginpage. | |
| if ( !strstr($referrer,'?login=empty') ) { // prevent appending twice | |
| wp_redirect( $referrer . '?login=empty' ); | |
| } else { | |
| wp_redirect( $referrer ); | |
| } | |
| } | |
| } | |
| } | |
| add_action( 'authenticate', 'custom_login_empty'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment