Question regarding hook_user_presave() and setting roles When a new user is created, either via admin or by normal user registration, I need to assign a custom role to that user.  It works fine, but I'm not convinced I've checked the user status enough.

In my hook_user_presave() implementation, I check to make sure the administration role isn't set, and uid isn't 1.  To set my role:

if ($account-&gt;uid == 1 || array_search('administrator', $account-&gt;roles))
        return;

$account-&gt;roles[] = 'my_custom_role';


I only want to do this if it is a brand new user being created/inserted.  The documentation says hook_user_presave() is called if the user is being updated.  What is the best way to check if this is a brand new user creation?  Would uid be set to 0?
The documentation for hook_user_presave() says the hook is invoked when an user account is updated, or created, not just when the user account is updated.

If you look at user_save(), you will notice that $account-&gt;is_new is set before invoking hook_user_presave(), when the user account is being created. If the account is being updated, $account-&gt;is_new is not set, and $account-&gt;original contains the user object before any changes.

In Drupal 8, $user-&gt;is_new will be replaced with Entity::isNew().