Tuesday, May 31, 2022
HomeWordPress DevelopmentAdd e mail addresses to already registered customers

Add e mail addresses to already registered customers


As a substitute of utilizing get_userdata, fetch the person itself as a WP_User object by way of get_user_by:

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

This provides you entry to all the fields of WP_User immediately, e.g.:

echo $user->user_login;

Which you’ll be able to then plug into your code

Doing this for all the opposite customers

WP_User_Query!

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

This is an instance from the docs that loops by means of each person with a clean e mail and shows their title:

$args = [
    'user_email' => '',
];
// The Question
$user_query = new WP_User_Query( $args );

// Consumer Loop
if ( ! empty( $user_query->get_results() ) ) {
    foreach ( $user_query->get_results() as $person ) {
        echo '<p>' . $user->display_name . '</p>';
    }
} else {
    echo 'No customers discovered.';
}

You may take away the echo and change it together with your verify that checks the e-mail is empty and updates the person.

Notice that since you’ve gotten quite a lot of customers, chances are you’ll must set 'quantity' => 100 and re-run the loop a number of instances till no customers with clean emails are discovered. That is to keep away from working out of reminiscence.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments