Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created August 3, 2016 13:17
Show Gist options
  • Save danielbachhuber/84f3b3887f21fc40517e5c088f212d4d to your computer and use it in GitHub Desktop.
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
<?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