Here's a patch that lets you do:

install_add_user('Mr. Jones', 's3cr3t', 'staff@example.com', array('staff'));

rather than:

$rid = install_get_rid('staff');
$roles[$rid] = 'staff';
install_add_user('Mr. Jones', 's3cr3t', 'staff@example.com', $roles);

I also PHPDoced the function, since it took me by surprise that it was trying to assign my users to role 0. ;)

Comments

webchick’s picture

hackwater’s picture

I've installed and used this patch, and I'm a big fan. It plays nicer with the profile as generated by the Profile Wizard.

boris mann’s picture

Status: Needs review » Reviewed & tested by the community

Webchick, this looks good -- can you please commit.

dww’s picture

Component: crud.inc » CRUD functions and includes
Assigned: Unassigned » dww
Status: Reviewed & tested by the community » Fixed

I ran into this same problem myself (#338182: Roles aren't properly associated with users) and just found this issue in the queue. ;) Re-rolled now that crud.inc has been split, added caching to install_get_rid() since that is now potentially going to be called a lot. Of course, this should still work even if the $roles array is already indexed by rid, and I tested that just to confirm. Committed to DRUPAL-6--1 and DRUPAL-5.

dww’s picture

Version: 5.x-1.x-dev » 5.x-2.x-dev

Based on #338323-1: Create an official release of 5.x-2.*, I backed out the crud.inc split in the DRUPAL-5 branch. This code is only fixed for D5 in the DRUPAL-5--2 branch now. ;)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.