Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Implementation of hook_user().
- */
- function realname_registration_user($op, &$edit, &$account, $category = NULL) {
- if ($op == 'insert') {
- // Generate the username based on first name and last name fields.
- $first_init = drupal_substr($edit['firstname'], 0, 1);
- $lastname = $edit['lastname'];
- $username = strtolower($first_init . $lastname);
- $orig = $username;
- $i = 0;
- // Check if the username already exists in the database.
- while (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE name = '%s';", $username))) {
- $username = $orig . ++$i;
- }
- $edit['name'] = $username;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement