Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. /**
  2.  * Implementation of hook_user().
  3.  */
  4. function realname_registration_user($op, &$edit, &$account, $category = NULL) {
  5.   if ($op == 'insert') {
  6.     // Generate the username based on first name and last name fields.
  7.     $first_init = drupal_substr($edit['firstname'], 0, 1);
  8.     $lastname = $edit['lastname'];
  9.     $username = strtolower($first_init . $lastname);
  10.     $orig = $username;
  11.     $i = 0;
  12.  
  13.     // Check if the username already exists in the database.
  14.     while (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE name = '%s';", $username))) {
  15.       $username = $orig . ++$i;
  16.     }
  17.  
  18.     $edit['name'] = $username;
  19.   }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement