Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

how to update current logged user username

Try hooking in as soon as the user is created or updated.

<?php

function wpse_250785_sync_user_login_with_email($user_id) {
    $user = new WP_User($user_id);

    if ($user->user_login != $user->user_email) {
        $user->user_login = $user->user_email;
        wp_update_user($user);
    }
}
add_action('user_register', 'wpse_250785_sync_user_login_with_email');
add_action('profile_update', 'wpse_250785_sync_user_login_with_email');

Disclaimer: Untested, but should work 😉

Related Posts:

  1. Custom user roles are unable to login
  2. Can I programmatically login a user without a password?
  3. What is $interim_login?
  4. Adding extra authentication field in login page
  5. What exactly is ReAuth?
  6. Login members using web services
  7. Disable WordPress 3.6 idle logout / login modal window / session expiration
  8. How to pass users back and forth using session data?
  9. Website Visible only to Registered users
  10. Need to execute a cron job
  11. moving server can not login
  12. Validate Custom Login field
  13. Calling wp_signon doesn’t log the user in
  14. How to implement Google reCaptcha without installing a plugin?
  15. How can I allow access to two user accounts using one login?
  16. Is it possible a one click user registration with Facebook or Twitter (or other Social Networks)?
  17. Are there ways of logging in that bypass wp-login.php altogether?
  18. Redirecting or displaying a message on first login
  19. How to display username and password after registration
  20. Password protect media attachment – share across guests
  21. WordPress login problem
  22. Two factor authentication
  23. How to generate “WP_Error” Object for user login?
  24. WordPress Login redirection according to user role
  25. How do you manage your pages or functions that require logged-in users?
  26. How to restrict access to a single for users I’ve authorized? [closed]
  27. Allow Access to Home Page and Login Screen but Nothing Else (unless logged in)
  28. Where is the php file, that does the checks for login information?
  29. I want login using email not username wordpress front end
  30. Reloading page with a query string upon login for admins
  31. Sign in with social media accounts without creating a WP account [closed]
  32. WordPress authentication using custom php?
  33. authenticate user without redirecting
  34. Multiple issues with Ajax login function due to browsers and cookies
  35. How to post frontend login form to a different authentication script from wp-login?
  36. Using WordPress login for a non word-press website
  37. Extend Cookie with auth_cookie_expiration not working
  38. Can we start session from another php site to wordpress blog site?
  39. How to password protect pages in WordPress
  40. How to lock WordPress front-end with login and password?
  41. Opening protected page with cookie?
  42. Handle POST request sent from an external site for login?
  43. External Authentication
  44. Creating Custom Login Form Where Password Field is Dropdown Menu
  45. Login and register by API
  46. In Django, how do I know the currently logged-in user?
  47. Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
  48. Is there any way to rename or hide wp-login.php?
  49. How to login with email only no username?
  50. How can I redirect user after entering wrong password?
  51. Increase of failed login attempts, brute force attacks? [closed]
  52. Login page ERROR: Cookies are blocked due to unexpected output
  53. Separate registration and login for different roles
  54. SSO / authentication integration with external ‘directory service’
  55. Preventing session timeout
  56. How reduce wordpress login session timeout time?
  57. How to prefill WordPress registration with social details
  58. Check for correct username on custom login form
  59. How to Change the Default Home Page for the WordPress Dashboard?
  60. Disallow user from editing their own profile information
  61. I can’t access my site via wp-admin
  62. ‘Password field is empty’ error when using autofill in Chrome
  63. Removing username from the ‘wordpress_logged_in’ cookie
  64. How to show ‘login error’ and ‘lost password’ on my template page?
  65. How do I require authorization / login to view a specific set of posts / pages?
  66. Custom login form
  67. How to prefill the username/password fields on the login page
  68. wp_signon returns user, but the user is not logged in
  69. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  70. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  71. wp_signon() does not authenticate user guidance needed
  72. What are the differences between wp_users and wp_usermeta tables?
  73. WordPress auto login after registration not working
  74. Make my wordpress blog remember my login “forever”
  75. How to check in timber if user is loggedin?
  76. How do I change the language of only the login page?
  77. Stop WordPress from logging me out (need to keep me logged in)
  78. Woocommerce registration page [closed]
  79. How to disable autocomplete on the wp-login.php page
  80. Share login data/cookies between multiple installations
  81. Synchronize WordPress user accounts across multiple domains and installations without using WordPress MU
  82. How do I change the logo on the login page?
  83. Why does WordPress hide the reset password key from the URL?
  84. Is it possible to sign in with user_email in WordPress?
  85. How to use current_user_can()?
  86. Avoid to load default WP styles in login screen
  87. WordPress registration message
  88. How to fake a WordPress login?
  89. how to display the wordpress login and register forms on a page?
  90. Does wp_logout_url() destroy a session? (Logging out question)
  91. How can I send a welcome email to a user AFTER they login for the first time?
  92. Can not login with correct username and password
  93. How can i increase the login expiration length?
  94. How do I use add_action from a class method?
  95. How to remove the WordPress logo from login and register page?
  96. How can I add a custom script to footer of login page?
  97. Brute force attack?
  98. Customize wp_new_user_notification_email()
  99. How to check WordPress website username and password is correct
  100. Login email after registration never sent or received
Categories login Tags authentication, login, user-access
Advanced Custom Fields into functions.php
Get_theme_mod not retrieving value

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress