You can equally use either [user_save][1]user_save()
or [field_attach_update][2]field_attach_update()
.
// Load the user's account.
global $user;
$account = user_load($user->uid); // Load user's account
$edit = $account->field_my_custom_field[LANGUAGE_NONE][0][value] = $new_value;
user_save($account, $edit);
// field_attach_update
$account->field_my_custom_field[LANGUAGE_NONE][0][value] = $new_value;
field_attach_update('user', $account);
The difference between those twousing one function or the other is that user_saveuser_save()
will update all the user fields whereas field_attach_updatefield_attach_update()
will update only the specified field.
[1]: https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_save/7.x
[2]: https://api.drupal.org/api/drupal/modules!field!field.attach.inc/function/field_attach_update/7.x