user_role_save

Versions
7
user_role_save($role)

Save a user role to the database.

Parameters

$role A role object to modify or add. If $role->rid is not specified, a new role will be created.

Return value

Status constant indicating if role was created or updated. Failure to write the user role record will return FALSE. Otherwise. SAVED_NEW or SAVED_UPDATED is returned depending on the operation performed.

Code

modules/user/user.module, line 2438

<?php
function user_role_save($role) {
  if ($role->name) {
    // Prevent leading and trailing spaces in role names.
    $role->name = trim($role->name);
  }
  if (!empty($role->rid) && $role->name) {
    $status = drupal_write_record('role', $role, 'rid');
    module_invoke_all('user_role_update', $role);
  }
  else {
    $status = drupal_write_record('role', $role);
    module_invoke_all('user_role_insert', $role);
  }

  // Clear the user access cache.
  drupal_static_reset('user_access');
  drupal_static_reset('user_role_permissions');

  return $status;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.