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. How to implement friend system for WordPress?
  33. Custom Query for count_user_posts function
  34. Delete user after Contact Form 7 submission [closed]
  35. Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
  36. How to pull all the contributer users records and order by Designation (which is users meta data)?
  37. cannot get user_registered date from get_user_meta
  38. Delete Users without a First and Last Name
  39. Display video on homepage for users who have not logged in
  40. Best way to get user id for get_users function?
  41. How to hide user profile fields based on the role of the viewed user?
  42. user_meta table in staging vs live site
  43. Customising “user ids” and add to ‘user’ panel in the admin area
  44. Add a sub menu page to the Users menu
  45. Get usermeta info from sql query
  46. Confirm Deletion not found
  47. Get current user array into hyperlink
  48. Privilege to recover trashed posts
  49. One Click Access To Users Account In WordPress?
  50. how do I add role and capability after I create a new user
  51. Get Authors Role
  52. How to use `wp_insert_user` & `wp_insert_post` simultaneously without `headers already sent` error?
  53. Need to exclude users with no posts from my contributors page
  54. Unexpected problems after importing WP data
  55. link variable to user
  56. How to parse a huge list of users using a CRON function?
  57. Changing user of post by changing ‘post_author’ field in ‘wp_posts’ table not taking effect. Where is the real post author info kept?
  58. WordPress user role with create user capability?
  59. How to safely trigger password reset emails for thousands of users
  60. How to add extra field in profile page and show in myaccount?
  61. Perform multiple actions after wp_insert_user()
  62. My custom user metadata is only active for only admin but i want it to be active on all users especially customers
  63. How to get image path from id using SQL
  64. Update user role for expired membership
  65. wp_insert_user error
  66. How to remember which page the user was on before logout?
  67. SQL to set Display Name to First Name + Last Name
  68. Create users by importing from CSV, with User ID assigned from CSV
  69. Moving users from joomla to wordpress
  70. User Group Level Login
  71. Deleted users still able to login
  72. Hook into add_user_role and update based on new and removed roles
  73. Limit user description length in characters
  74. Auto approve new users if their username is included in a predefined list
  75. How to update user meta from php file?
  76. Check for empty username or password on login
  77. How do I tag every author in their posts that they have made previously
  78. Updated user role inncorrect when using wp_get_current_user()
  79. How to create members?
  80. How to use url formatter with integer
  81. Custom registration fields not appearing in user info
  82. Show user details only
  83. add a Custom Columns to user
  84. Creating custom pages for new users automatically
  85. Output checkbox per user and save in plugin options
  86. Require confirmation of current user’s email before updating database and before send_email_change_email
  87. get_user_by asking for string while string is given
  88. Access level seems to have gone from admin to editor
  89. How do I change the user via SQL?
  90. post acces for guests / unregistered users only
  91. User list order by user meta
  92. What’s the most secure way to grant a user permission to update in a multisite?
  93. User email not being changed (cached?) until next page load (frontend)
  94. logged_in user outside of wordpress loop
  95. Modify Profile Biographical Info Field
  96. Problem with update_user_meta() meta_value
  97. MySQL query to list users who never signed in
  98. Send email to user if their role is changed to Author
  99. Can’t retrieve user email address with REST API
  100. How can I set a tag when a user registers in wordpress via gravity forms [closed]
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
  • 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