How to programmatically assign user roles
I am assigning a role to user by this code:
$user = user_load($user->uid); $role = user_role_load_by_name("10-dis"); $user->roles = $user->roles + array($role->rid => $role->name); user_save($user);
I need to replace this role with a new role, means I need to change user role according to some condition. How can I programmatically reassign user role?
This article was republished from its original source.
Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.