/ Published in: PHP
Create new user account programmatically - drupal 7
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * * Criar nova conta * * @param $email * @return bool */ function _create_user_account($email) { //This will generate a random password, you could set your own here $password = user_password(8); //set up the user fields. In this case username = mail. 'name' => $email, 'mail' => $email, 'pass' => $password, 'status' => 1, 'init' => 'email address', DRUPAL_AUTHENTICATED_RID => 'authenticated user', ), ); //the first parameter is left blank so a new user is created $account = user_save('', $fields); // Manually set the password so it appears in the e-mail. $account->password = $fields['pass']; // Send the e-mail through the user module. drupal_mail('user', 'register_no_approval_required', $email, NULL, array('account' => $account), variable_get('site_mail', '[email protected]')); return TRUE; } else { return FALSE; } }