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. ;)
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | install_profile_api-easier-add-user-function-174323-1.patch | 1.59 KB | webchick |
Comments
Comment #1
webchickPatch.
Comment #2
hackwater commentedI've installed and used this patch, and I'm a big fan. It plays nicer with the profile as generated by the Profile Wizard.
Comment #3
boris mann commentedWebchick, this looks good -- can you please commit.
Comment #4
dwwI 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.
Comment #5
dwwBased 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. ;)