How to remove user role using hook_user_update I am having trouble trying to remove a role after user account submit.

I have used the following code:

function vdb_form_alter(&amp;$form, $form_state,  $form_id) {
  global $user;


}
  if(($form_id === 'user_profile_form')and (isset($form['account']['pass'])) and (in_array('Hybridauth', array_values($user-&gt;roles))) ) {
      $form['#submit'][] = 'my_module_hook_user_update';


}
function my_module_hook_user_update($edit, $account, $category) {
  $role_position = array_search('Hybridauth', $account-&gt;roles);
  // Use !== or === here since $role_position may be zero or FALSE
  if ($role_position !== FALSE) {
    unset($account-&gt;roles[$role_position]);
  }
}


Resulting in the following errors:

Warning: Missing argument 3 for vdb_hook_user_update(), called in \includes\form.inc on line 1471 and defined in vdb_hook_user_update() (line 46 
Notice: Trying to get property of non-object in vdb_hook_user_update() (line 47 
Warning: array_search() expects parameter 2 to be array, null given in vdb_hook_user_update() (line 47 
Warning: Attempt to modify property of non-object in vdb_hook_user_update() line 50

I have tried using hook_user_presave however using this hook hybridauth module gets stuck.
The errors in your code are two:


vdb_hook_user_update() is not the correct name for an implementation of hook_user_update()
vdb_hook_user_update() is being used as form submission handler


As consequence of the second point is that you are declaring the function with the wrong arguments, since a form submission handler gets two arguments: $form and &amp;$form_state.

As Clive pointed out, you should use hook_user_presave(), which is invoked before the user account is saved in the database. Remove the code adding the form submission handler, and implement hook_user_presave() using code similar to the following one.

function vd_user_presave(&amp;$edit, $account, $category) {
  if (!empty($account-&gt;uid) &amp;&amp; ($key = array_search('Hybridauth', $account-&gt;roles)) !== FALSE) {
    unset($account-&gt;roles[$key]);
  }
}