Text Size
Sunday, May 20, 2012
Get a look down
Joomla >> Code snippets >> How to assign a role to a user in Drupal programatically
Monday, 18 July 2011 14:09

How to assign a role to a user in Drupal programatically

Written by Nabil Sadki
Rate this item
(0 votes)

With this little code, you can assign many roles to a specified user :

1
2
3
4
5
6
7
8
9
10
// Here's an example of how to assign two roles to a user
$usr = user_load($uid); // $uid is the user ID
$roles = array(
	'uid' => $uid,
	'roles' => array(
		10 => 'Supervisor', // 10 is the role ID
		17 => 'Author'
		)
	);
user_save($usr, $roles);
Last modified on Saturday, 30 July 2011 00:43
Nabil Sadki

Nabil Sadki

Hello, I am Nabyl, a Freelance web developer and a joomla addict. I have made many sites using the latter, but also patches for the core of this CMS. I like HipHop culture and world of warcraft. You can find find me on Twitter when i'm free...

Website: www.coins.ma E-mail: This e-mail address is being protected from spambots. You need JavaScript enabled to view it

Add comment



Usefull tricks