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

Add email addresses to already registered users

Doing This For a Single User In The user_register Filter

Instead of using get_userdata in your filter, fetch the user itself as a WP_User object via get_user_by:

$user = get_user_by( 'id', $user_id );

This gives you access to all of the fields of WP_User directly, e.g.:

echo $user->user_login;

Which you can then plug into your code

Doing this for all the other users

You should use WP_User_Query to fetch an array of users that do not have emails ( assuming the email is an empty string ). This would not happen inside your filter and is a separate independent piece of code.

https://developer.wordpress.org/reference/classes/wp_user_query/

Here’s an example from the docs that loops through every user with a blank email and displays their name:

// The Query
$user_query = new WP_User_Query( [] );

// if users were found
if ( ! empty( $user_query->get_results() ) ) {
    // then for each user
    foreach ( $user_query->get_results() as $user ) {
        // if it already has an email, skip it
        if ( ! empty( $user->user_email ) ) {
            continue;
        }

        // otherwise, add an email here...
    }
} else {
    echo 'No users found.';
}

You can remove the echo and replace it with your check that tests the email is empty and updates the user.

Note that since you have a lot of users, you may need to set 'number' => 200, 'paged' => 1, in the WP_User_Query arguments, and re-run the loop several times with paged set to higher numbers. This is to avoid running out of memory.

Related Posts:

  1. Send Email to Users after Deleting Account
  2. how can i inform other users about new user registration? [closed]
  3. get_user_meta() doesn’t include user email?
  4. Confirmation required on email change
  5. Email user when password is reset by admin
  6. How to set up User email verification after Signup?
  7. How can I get users email (and additional data) from the rest API?
  8. How to discover and delete unused accounts?
  9. Send activation email to user after signup [duplicate]
  10. Buddypress – Send New User Activation Link to Admin [closed]
  11. Adding second Email address for WP user notifications
  12. How can I check if a user’s email exists in the database
  13. Suddenly all emails in User have [email protected]
  14. Translate emails into the language of the user
  15. How to notify specific users when i’m posting/modifying a new post
  16. Unable to change email address of admin on localhost
  17. Send email to all registered users [closed]
  18. how to remove email field from default user registration form on wordpress
  19. What is correct way to change user’s email?
  20. Send clear password via mail
  21. Need to manually add multiple WP users with same e-mail address (with good reason)
  22. WP Create User – Preventing repeated information
  23. User with same Mail but a different additional info(like domain)
  24. How do I update user email from frontend input field?
  25. Custom Password Reset
  26. Send user auto generated password on different email
  27. User email verification without a plugin, is it possible?
  28. Exclude Current user email and send notification
  29. New User Registration email
  30. Email Subscribe for Downloads in WordPress
  31. Remove My Account Menu items in Woocommerce based on user roles
  32. Condionally/limited emails from system (cantact-form, registration, passwd reset)With
  33. If the current user is an administrator or editor
  34. How to change the default registration email ? (plugin and/or non-plugin)
  35. Editor can create any new user except administrator
  36. How do I add a field on the Users profile? For example, country, age etc
  37. How do I display logged-in username IF logged-in?
  38. How to allow an user role to create a new user under a role which lower than his level only?
  39. user_login vs. user_nicename
  40. How to programatically change username (user_login)?
  41. Change the Author Slug from Username to Nickname
  42. Remove Ability for Other Users to View Administrator in User List?
  43. Difference between update_user_meta and update_user_option
  44. Make display name unique
  45. Make WooCommerce pages accessible for logged in users only
  46. Find out if logged in user is not subscriber
  47. WordPress usermeta scaling for thousands of users
  48. How to get WordPress Username in Array format
  49. Display user registration date
  50. Get multiple roles with get_users
  51. How to Merge Two Authors Into One?
  52. Whats the best way to share user data across multiple WordPress websites?
  53. get_current_user_id() returns 0?
  54. How to get userid at wp_logout action hook?
  55. Groups of capabilities: users with multiple roles?
  56. Is there a way to merge two users?
  57. User-edit role setting distinct from wp_capabilities? [closed]
  58. List users by last name in WP_User_Query
  59. What’s the difference between the capability remove_users and delete_users?
  60. How to restrict access to uploaded files?
  61. Automatically delete inactive users after 2 months
  62. How to change user_login with wp-cli?
  63. Delete all subscribers from wp_users and wp_usermeta a few thousand at a time
  64. Replacing the WordPress password validation
  65. Ban a user and end their session
  66. Allowing users to edit only their page and nobody else’s
  67. How can 2 blogs share the same users
  68. alphabetically order role drop-down selection in dashboard
  69. WordPress auto login after registration not working
  70. Change the author slug from nickname to ID
  71. Execute a function when admin changes the user role
  72. How to let contributors to create a new revision(draft) editing their published posts
  73. how to use joomla password format in wordpress?
  74. How to do get_users() with multiple meta_keys
  75. Disallowing Users of a Custom Role from Deleting or Adding Administrators?
  76. What the user_status column?
  77. How to limit users to one comment per post
  78. Different back-end language for different users?
  79. Hide Admin Menu for Specific User ID who has administrator Role
  80. Migrating WordPress users into Disqus
  81. Problem with Hebrew characters in username
  82. Is there an upper limit for users in WP?
  83. How to display the status of users (online – offline) in archive.php
  84. Remove email verification when new user register
  85. How to change user`s avatar?
  86. Allow up to 5 Concurrent Login Sessions
  87. How to let user set password on registration
  88. How to hide media uploads by other users in the Media menu?
  89. Show admin bar only for some USERS roles
  90. How to display custom user meta from registration in backend?
  91. Allowing an email as the username?
  92. How to work around “that email address has already been used” error?
  93. Get the name of user who updated post
  94. Disable delete user
  95. Grouping users under parent user
  96. How to get the Gravityform entry ID from current user’s form submission? [closed]
  97. Retrieve all users from wordpress database via REST/JSON API
  98. Is there a way to set a user profile to Draft?
  99. Display edit link if post author is current user
  100. Check if specific username is logged in
Categories users Tags account, email, users
What is a good member directory plugin? [closed]
Force logout ALL users at a certain time

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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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