Art of Coding

Web development tips and tricks

  • WordPress
    • Multiple post images
    • Social Sharing
  • Php
  • Javascript
  • Networking
  • Linux / Unix
  • Git
  • Get in touch

Allow user to login with email address

On May 20, 2015 By Ankit Tiwari In Wordpress Tips and Tricks

We can easily enable wordpress users to login using email id. To do this, we can use the hook “authenticate”

Simply copy the following snippet in your plugin or functions.php file

add_filter('authenticate', 'allow_email_login', 20, 3);

function allow_email_login( $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 );

}

Recent Posts

  • Configure xdebug in docker to use with netbeans February 19, 2021
  • Share files between iPad and Windows PC January 31, 2020
  • WP CLI error “No such file or directory” January 18, 2020
  • WordPress file upload with AJAX May 15, 2019
  • A simple way to encrypt/decrypt data in php November 27, 2018

Categories

  • General PHP Tips
  • Git
  • Javascript and jQuery
  • Linux Tips
  • Networking
  • Wordpress Tips and Tricks

Copyright All rights reserved