Created
August 3, 2016 13:17
-
-
Save danielbachhuber/84f3b3887f21fc40517e5c088f212d4d to your computer and use it in GitHub Desktop.
Display email address instead of the user_login when user is already logged in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'wp_login_errors', function( $errors ){ | |
$GLOBALS['hb_backup_user_login'] = null; | |
if ( ! empty( $GLOBALS['user_login'] ) && empty( $_POST['log'] ) ) { | |
$GLOBALS['hb_backup_user_login'] = $GLOBALS['user_login']; | |
$GLOBALS['user_login'] = wp_get_current_user()->user_email; | |
} | |
return $errors; | |
}); | |
add_action( 'login_form', function(){ | |
if ( ! is_null( $GLOBALS['hb_backup_user_login'] ) ) { | |
$GLOBALS['user_login'] = $GLOBALS['hb_backup_user_login']; | |
$GLOBALS['hb_backup_user_login'] = null; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment