WordPress.org

Ready to get started?Download WordPress

Forums

SimpleModal Login
How to set Username to Email (4 posts)

  1. gplatt
    Member
    Posted 3 years ago #

    Hi,

    I'd like to hide the username field all together for registration and login and just use email.

    Could you give me some pointers to accomplish this please? I obviously need to hide the username fields on your screen and then assign the value programmatically, however I haven't been able to get this to work.

    Many thanks
    Guy

    http://wordpress.org/extend/plugins/simplemodal-login/

  2. Eric Martin
    Member
    Plugin Author

    Posted 3 years ago #

    The easiest way to do this might be to add the following code to your theme's functions.php file:

    function mytheme_login_form($form) {
    	return str_replace('Username', 'Email', $form);
    }
    add_filter('simplemodal_login_form', 'mytheme_login_form');
    
    function mytheme_authenticate_username_password($user, $username, $password) {
    	$user = get_user_by_email($username);
    	if ($user) {
    		$username = $user->user_login;
    	}
    
    	return wp_authenticate_username_password(null, $username, $password);
    }
    remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
    add_filter('authenticate', 'mytheme_authenticate_username_password', 20, 3);

    The code above will change Username to Email and then use the email to try and retrieve the user.

    This doesn't include email validation and your client-side messages may still say username instead of email...but it's a start.

  3. gplatt
    Member
    Posted 3 years ago #

    Many many thanks for the help. I'll go see what I can do.

  4. MG7282
    Member
    Posted 3 years ago #

    This is great, but it doesn't remove the UserName field from 'Registration'. How can it me removed there as well?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic