function _commons_create_demo_users in Drupal Commons 7.3
BatchAPI callback.
See also
commons_demo_content()
1 string reference to '_commons_create_demo_users'
- commons_install_additional_modules in ./
commons.install - Task callback: uses Batch API to enable modules based on user selection.
File
- ./
commons.install_callbacks.inc, line 23 - Contains Batch API callbacks used during installation.
Code
function _commons_create_demo_users($operation, &$context) {
$context['message'] = t('@operation', array(
'@operation' => $operation,
));
// Reset the Flag cache.
flag_get_flags(NULL, NULL, NULL, TRUE);
// Create an array of usernames.
$demo_usernames = array(
'Jeff Noyes',
'Drew Robertson',
'Lisa Rex',
'Katelyn Fogarty',
'Dharmesh Mistry',
'Erica Ligeski',
);
// Create a user for each username.
foreach ($demo_usernames as $username) {
list($first_name, $last_name) = explode(" ", $username);
$normalized_username = commons_normalize_name($username);
$password = user_password(8);
$fields = array(
'name' => $username,
'mail' => "{$normalized_username}@example.com",
'pass' => $password,
'status' => 1,
'init' => "{$normalized_username}@example.com",
'roles' => array(
DRUPAL_AUTHENTICATED_RID => 'authenticated user',
),
);
$fields['field_name_first'][LANGUAGE_NONE][0]['value'] = $first_name;
$fields['field_name_last'][LANGUAGE_NONE][0]['value'] = $last_name;
$user = user_save(NULL, $fields);
// Add an avatar to the user account.
commons_add_user_avatar($user);
$context['results']['users'][$username] = $user;
}
}