Is there a module that allows users to have a display name instead of a username?

I'm making a site for a local organization, so it's important that the site show real names.
While I was running a test site, it quickly became apparent that nearly EVERY volunteer wanted to use their usual online nick as a username, because they could remember it. So I had users called 'jon234' or whatever, and when I insisted they use real names they forgot their login details.

I know I could stick in a profile field and use theming to overrite theme_username(), but I'd like something that works across all themes and doesn't need maintaining.

Comments

Anonymous’s picture

Add a profile field for full name, you need to store it somewhere.

Rather than pulling that in a theme, add this to template.php which is global to all themes.

/**
* Catch the theme_user_profile function
*/
function phptemplate_user_profile($user, $fields = array()) {
return _phptemplate_callback('user_profile', array('user' => $user, 'fields' => $fields));
}

Then create a new file (in your theme folder) called user_profile.tpl.php - with the code of that function in the user.module as a starting point, modify it to get the user profile looking the way you want. I often setup the profile fields, and then place them specifically in this file.

Here's a sample, placing a first name / last name profile fields into specific areas on the page...

<?php
$profuser = user_load(array('uid' => arg(1)) );  //user whose page we are on
global $user;  //user who is looking at the profile
?>
<div>
<?php if ( $profuser->profile_lname ) { print '<h3>'.$profuser->profile_fname.' '.$profuser->profile_lname.'</h3>'; } ?> 
<?php print theme('user_picture', $profuser); ?>
</div>
joachim’s picture

I actually want to change all instances of a user's name -- on node "created by" text, comments, etc.

poundy’s picture

subscribing

thomjjames’s picture

Hi,

Think you need to overide the theme_username function and grab the name from the profile module:

/**
 * add to template.php
 */
function phptemplate_username($object) {
  $object = profile_load_profile($object);
  $object->name = $object->profile_real_name;  

  if ($object->uid && $object->name) {
    // Shorten the name when it is too long or it will break many tables.
    if (drupal_strlen($object->name) > 20) {
      $name = drupal_substr($object->name, 0, 15) .'...';
    }
    else {
      $name = $object->name;
    }

    if (user_access('access user profiles')) {
      $output = l($name, 'user/'. $object->uid, array('attributes' => array('title' => t('View user profile.'))));
    }
    else {
      $output = check_plain($name);
    }
  }
  else if ($object->name) {
    // Sometimes modules display content composed by people who are
    // not registered members of the site (e.g. mailing list or news
    // aggregator modules). This clause enables modules to display
    // the true author of the content.
    if (!empty($object->homepage)) {
      $output = l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
    }
    else {
      $output = check_plain($object->name);
    }

    $output .= ' ('. t('not verified') .')';
  }
  else {
    $output = variable_get('anonymous', t('Anonymous'));
  }

  return $output;
}

I've not tested this but worth a try
Cheers
Tom
______________________________________________
http://drupalsn.com/user/thomjjames

______________________________________________
https://tomswebstuff.com

pjaxon’s picture

I added two fields to my user profile (field_first_name and field_first_name) and then I added a preprocess function in template.php like so:

function theme_username_alter(&name, $account) {
  if (isset($account->uid)) {
    $this_user = user_load($account->uid);//loads the custom fields
    $name = $this_user->field_first_name['und'][0]['value'].' '.$this_user->field_last_name['und'][0]['value'];
  }
}

There are other ways to do the same thing, but this worked for me.

johan den hollander’s picture

This works for me:

function themename_username_alter(&$name, $account) {
  if (isset($account->uid)) {
    $this_user = user_load($account->uid);
		$display_name = $this_user->field_user_display_name[LANGUAGE_NONE][0]['safe_value'];
		if (isset($display_name) && !empty($display_name)) {
			$name = $display_name;
		}
  }
}