Checking for user by email

Okay, I have data coming via a webhook, in there I can get all the details I need, including the email address.

So using “get_user_by” how do I find their userid?

$thisuserid = get_user_by(???, $_REQUEST[‘email’]);
Is it like that?

You’d get the WP_User object. https://developer.wordpress.org/reference/functions/get_user_by/#comment-494

$user = get_user_by('email', $_REQUEST[‘email’]);
// $user->id

Okay, I had to create a function for it, to get it to work:

function get_user_by( $field, $value ) {
    $userdata = WP_User::get_data_by( $field, $value );

    if ( ! $userdata ) {
        return false;
    }
 
    $user = new WP_User;
    $user->init( $userdata );
 
    return $user;
}

So now it works. odd that I had to do that.

How would I then get the ROLE of the user with their ID?

can I get it from that $user data returned?

I got it. nevermind. :slight_smile: