Created
March 13, 2024 07:14
-
-
Save getneerajk/3d8c68153a47b2a0d70f6f1627169d98 to your computer and use it in GitHub Desktop.
Case sensitive username #hook #filer
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 | |
function login_case_sensitive( $user, $username, $password ) { | |
$user_id = username_exists($username); | |
if( !$user_id ) { | |
return $user; | |
} | |
$user_obj = get_user_by('id', $user_id); | |
if( $username !== $user_obj->user_login ) { | |
return new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: Invalid username or password.' ) ); | |
} | |
return $user; | |
} | |
add_filter( 'authenticate', 'login_case_sensitive', 20, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment