Skip to content

Instantly share code, notes, and snippets.

@getneerajk
Created March 13, 2024 07:14
Show Gist options
  • Save getneerajk/3d8c68153a47b2a0d70f6f1627169d98 to your computer and use it in GitHub Desktop.
Save getneerajk/3d8c68153a47b2a0d70f6f1627169d98 to your computer and use it in GitHub Desktop.
Case sensitive username #hook #filer
<?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