BuddyDev

Search

[Resolved] Login With Email Only

Tagged: 

  • Participant
    Level: Master
    Posts: 171
    JohnnyNW on #26452

    Okay, so I found a plugin called Force Email Login, though it hasn’t been updated since WP 4.7 (3 years ago I believe, if my Spanish is still working)… .

    It seems to work with no issues, works quite nice, but the only code the plugin has is this:

    <?php
    /*
    Plugin Name: Force Email Login
    Author: Takayuki Miyauchi
    Plugin URI: https://github.com/miya0001/force-email-login
    Description: Use email address for login to your WordPress.
    Version: 0.6.0
    Author URI: https://miya.io/
    */
    
    $force_email_auth = new Force_Email_Auth();
    $force_email_auth->register();
    
    class Force_Email_Auth {
    
    	function register()
    	{
    		add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
    	}
    
    	public function plugins_loaded()
    	{
    		remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
    		add_filter( 'authenticate', array( $this, 'authenticate'), 20, 3 );
    	}
    
    	public function authenticate( $user, $username, $password )
    	{
    		if ( is_a( $user, 'WP_User' ) ) {
    			return $user;
    		}
    
    		if ( ! empty( $username ) && is_email( $username ) ) {
    			$user = get_user_by( 'email', $username );
    			if ( isset( $user, $user->user_login, $user->user_status ) ) {
    				if ( 0 === intval( $user->user_status ) ) {
    					$username = $user->user_login;
    					return wp_authenticate_username_password( null, $username, $password );
    				}
    			}
    		}
    
    		if ( ! empty( $username ) || ! empty( $password ) ) {
    			return false;
    		} else {
    			return wp_authenticate_username_password( null, "", "" );
    		}
    	}
    }
    

    Yet, far as I can tell it should work with WP 5.2.4 (I don’t want to upgrade to WP 5.3, just not feeling it LOL).

    It seems to work well with all of your BuddDev plugins… .

    Thank you.

  • Keymaster
    (BuddyDev Team)
    Posts: 21852
    Brajesh Singh on #26459

    Hi,
    We have explicit support for that plugin in ajax registration. I don’t remember if we have it in branded login or not.

    I am glad it is working fine.

    PS:- I too upgrade normally after a week of the major release of WordPress. That saves a lot of trouble.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved