[PHP - WordPress] Eseguire il login con username o email

Aggiungendo il seguente snippet all'interno del file functions.php del vostro tema WordPress darete la possibilitą ai vostri utenti di loggati tramite username o email.
Il secondo snippet cambia invece l'etichetta "Username" in "Username/Email" ma ovviamente sentitevi liberi di modificarla a vostro piacimento.

 
function login_with_email_address($username) {
        $user = get_user_by('email',$username);
        if(!empty($user->user_login))
                $username = $user->user_login;
        return $username;
}
add_action('wp_authenticate','login_with_email_address');
function change_username_wps_text($text){
       if(in_array($GLOBALS['pagenow'], array('wp-login.php'))){
         if ($text == 'Username'){$text = 'Username / Email';}
            }
                return $text;
         }
add_filter( 'gettext', 'change_username_wps_text' );