Last Updated: February 25, 2016
·
478
· darvein

Add rol to a drupal user

This is an example of how we can add a new rol to a drupal user:

// First load the actual drupal user
global $user;

// The name of the role to add.
$role_name = 'graphic_designer'; 

if ($role = user_role_load_by_name($role_name)) {
  user_multiple_role_edit(array($user->uid), 'add_role', $role->rid);
}