Created
May 14, 2019 22:24
-
-
Save WPprodigy/7c4a33849de07b8344ba1768f12d8319 to your computer and use it in GitHub Desktop.
Give a default error message when login attempt failed.
This file contains 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 | |
/** | |
* Return a more abstract error message when an invalid password was entered but for a valid username. | |
* | |
* @param null|WP_User|WP_Error $user WP_User if the user is authenticated, WP_Error or null otherwise. | |
*/ | |
add_filter( 'authenticate', function( $user ) { | |
if ( is_wp_error( $user ) && 'incorrect_password' === $user->get_error_code() ) { | |
$user = new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: Invalid username, email address or incorrect password.' ) ); | |
} | |
return $user; | |
}, 999, 1 ); | |
/** | |
* Return a more abstract error message for when invalid passwords, usernames, or emails are entered. | |
* | |
* @param null|WP_User|WP_Error $user WP_User if the user is authenticated, WP_Error or null otherwise. | |
*/ | |
add_filter( 'authenticate', function( $user ) { | |
if ( is_wp_error( $user ) && in_array( $user->get_error_code(), array( 'incorrect_password', 'invalid_email', 'invalid_username' ), true ) ) { | |
$user = new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: Invalid username, email address or incorrect password.' ) ); | |
} | |
return $user; | |
}, 999, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment