Skip to content

Instantly share code, notes, and snippets.

@qutek
Created March 5, 2015 07:49
Show Gist options
  • Save qutek/462792ee0e43b16bca47 to your computer and use it in GitHub Desktop.
Save qutek/462792ee0e43b16bca47 to your computer and use it in GitHub Desktop.
[Wordpress] Allow user login with email
<?php
/**
* login_with_email filter to the authenticate filter hook, to fetch a username based on entered email
* @param obj $user
* @param string $username [description]
* @param string $password [description]
* @return boolean
*/
add_filter('authenticate', 'login_with_email', 20, 3);
function login_with_email( $user, $username, $password ) {
if ( is_email( $username ) ) {
$user = get_user_by_email( $username );
if ( $user ) $username = $user->user_login;
}
return wp_authenticate_username_password(null, $username, $password );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment