How can I get users email (and additional data) from the rest API?

To add the user’s email address in the REST API response, register an additional field to the user object and add the email address:

register_rest_field(
    'user',
    'user_email',
    [
        'get_callback' => static function (array $user): string {
            return get_userdata($user['id'])->user_email;
        },
    ]
);

Please note, however, that this is strongly discouraged because anyone can then see the email addresses if the code is running on a publicly accessible website.

Leave a Comment