The trick here is using the $op “insert” as it is only called once upon user creation.
For a very basic example of using hook_user(), here is how you would create a new node for the new user. Useful for automatically creating a new user’s content_profile node. This is pretty much just programmatic node creation inside of hook_user’s insert $op.
Applying a new role to the user. Useful for many things. You could potentially have a profile question on user registration and use the given answer to determine the role the user should receive.
Now, let’s give the user a role based on a profile field.
I’ve created a profile field named profile_role and made it a select list with the options being Normal User and Business Owner. This case is only slightly different from the previous, in that we need to load the account’s profile information, and look at the profile_role field to decide what to do.
For the final example, we will block new business owners so that they require admin approval. This is something I’ve found myself doing on multiple sites recently.
Assume we have a website where the user base is divided into two primary roles. The first being the standard authenticated users, and the other users having a business owner role. A business owner has way more permissions than an authenticated user, so we want to require all business owners to be approved, while allowing standard users to skip approval.
There we have it. Programmatically giving a new user a role based on a profile field, and requiring that user to be approved by the admin.