Skip to content

trepmal.com

  • Home
  • Plugins
  • Github
  • Me on WP.org
  • Donate

Categories

  • WordPress Bits (149)
  • Uncategorized (11)
  • Scripts (5)
  • Tidbits (5)
  • Fun (3)

Tags

  • wordpress (30)
  • administration (16)
  • plugin (9)
  • free download (8)
  • functions.php (8)

Year

  • 2018 (8)
  • 2016 (2)
  • 2015 (4)
  • 2014 (19)
  • 2013 (11)

Filter Hook: authenticate

Allow Users to Log In with Registered Email Address

It seems to be more and more common to see sites that allow users to log in with their username or email address.

Here’s how to add that ability to WordPress

//remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
add_filter('authenticate', 'wp_authenticate_username_password_redux', 20, 3);
function wp_authenticate_username_password_redux( $user, $username, $password ) {
    if ( is_email( $username ) ) {
        $user_obj = get_user_by_email( $username );
        if ( $user_obj ) $username = $user_obj->user_login;
    }
    return wp_authenticate_username_password( $user, $username, $password );
}

* works with or without the remove_filter line.

Posted on April 27, 2011March 1, 2012Categories WordPress BitsTags authentication, log in1 Comment on Allow Users to Log In with Registered Email Address
Proudly powered by WordPress