I’m trying to fork this plugin to use the user email to login, as opposed to Username.
The plugin is http://wordpress.org/plugins/wp-modal-login/
Is there a nice way to do this, perhaps by a filter to get this plugin to work with email credentials?
I’ve tried using this filter:
function custom_login() {
$data = array();
$data['user_login'] = sanitize_user( $_REQUEST['username'] );
$data['user_email'] = sanitize_user( $_REQUEST['user_email'] );
$data['user_password'] = sanitize_text_field( $_REQUEST['password'] );
$data['rememberme'] = sanitize_text_field( $_REQUEST['rememberme'] );
$data['user_login'] = sanitize_user( $_REQUEST['user_email'] );
$user = wp_signon( $creds, false );
if ( is_wp_error($user) )
echo $user->get_error_message();
}
// run it before the headers and cookies are sent
add_action( 'after_setup_theme', 'custom_login' );
2 Answers
I’m using this simple action, and it works like a charm. 🙂
<?php
/** Plugin Name: (#111223) User Login with Mail Address */
  add_action( 'wp_authenticate', 'wpse111223_login_with_email_address' );
function wpse111223_login_with_email_address( $username ) {
$user = get_user_by_email( $username );
if ( ! empty( $user->user_login ) )
$username = $user->user_login;
return $username;
}
It hooks to wp_authenticate and enables email login to the WordPress Authentication system, so it should work with any plugin. I use it successfully with Login with Ajax plugin.
🙂
Later-edit: For those who don’t know where to put the snippet of code, it should go in your theme’s functions.php
or a custom plugin.