7.x user.api.php hook_user_update(&$edit, $account, $category)

A user account was updated.

Modules may use this hook to update their user data in a custom storage after a user account has been updated.


$edit: The array of form values submitted by the user.

$account: The user object on which the operation is performed.

$category: The active category of user information being edited.

See also



Related topics

2 functions implement hook_user_update()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entity_crud_hook_test_user_update in modules/simpletest/tests/entity_crud_hook_test.module
Implements hook_user_update().
trigger_user_update in modules/trigger/trigger.module
Implements hook_user_update().
2 invocations of hook_user_update()
field_attach_update in modules/field/field.attach.inc
Save field data for an existing entity.
user_save in modules/user/user.module
Save changes to a user account or add a new user.


modules/user/user.api.php, line 293
Hooks provided by the User module.


function hook_user_update(&$edit, $account, $category) {
    'uid' => $account->uid,
    'changed' => time(),


ncatdesigner’s picture


I implemented hook_user_update in a module and I'm executing a shell script after this that collect all kind of data.

The problem is that when I do so, the data is not still updated.

I'm using Field API and my question is, it is possible that field API values are updated AFTER hook_user_update?


danielb’s picture

Not according to the code in user_save() that handles all this.

walkah’s picture

By the time we get to hook_user_update, $edit and $account are actually the same. If you need to check for changed values, compare $account and $account->original instead.

jomarocas’s picture

thanks for your comments

 * Implements hook_user_update().
function country_app_email_user_update(&$edit, $account, $category) {
  if ($account->field_['und'][0]['value'] !=  $account->original->field_['und'][0]['value']) {
    dpm('no change');
ermanpoe’s picture

Is $category help me to see wich form invoke my hook ?

I have a custom script who save my user and i don't want my notification mail to be send when i use this custom script. ( i invoke drupal_mail in my hook_user_update )

Thanks for your help.

RedEight’s picture

Not that I know of. I implemented the hook and threw in some debug to see what $category was for both situations (existing user profile form submitted or custom script) and in both cases the value of $category was "account". I know it is supposed to be contextual information, but it seems like it only relates to the type of data being saved and not where the data came from...

lukasss’s picture

$account may take on different values!
For example, if a batch is added as page admin/people:
2 (String, 18 characters ) authenticated user
64 (String, 4 characters ) GOLD
65 (String, 8 characters ) PLATINUM

But in page user/*/edit?destination=admin/people:
64 (String, 2 characters ) 64
65 (String, 2 characters ) 65
2 (Boolean) TRUE

I think this is not right

michaellenahan’s picture

@walkah thank you. To act upon a user being blocked, I am using the following code:

function MODULENAME_user_update(&$edit, $account, $category) {
  if ($account->status === '0' && $account->original->status === '1') {
    // User is being blocked.
Lanci’s picture

Hello everyone,
I am wondering if it is possible to make some test and then prevent Drupal to perform the update from within this hook.
Anyone has already tried something similar?

Thank you in advance!