SHARE
TWEET

Untitled

a guest Jul 17th, 2017 39 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
Top