[Drupal] How to get the data of a user when the user has updated their profile

| | 1 min read

We wanted to get the value of a field in a users profile in a Drupal site when they become a subscriber (when they got the subscriber role). Since we are very familiar with Drupal we intuitively searched for a hook that we would serve our purpose. Read on to know how to get the data of a user when the user has updated their profile

The hook that best serves this function is

hook_user_update

This account provides 3 parameters,

  • $edit: The array of submitted form values by the user.
  • $account: The operation to perform on user object.
  • $category: The active category of user information being edited.

As you can see the $account parameter holds the value of the fields in a users profile. You can get the value of a field say field_referral_user_data by calling the hook in the following format,

$account->field_referral_user_data

We have only scratched the surface of the hook. There are many other functions that this hook serves. Let me know if you found another better user for this hook from your comments