Keep Drupal from Truncating User Names

On some sites with very mixed audiences I try to get people to use their full names as user names. Sometimes, couples share an account, and then I try to get them to use both of their names. This can result in some very long user names, and Drupal has a nasty habit of truncating after 15 characters.

Consider a couple with a user name of "Jane Doe and John Smith" — John probably won't be happy to get truncated...

To fix this for phptemplate themes, create or add to themes/your_theme/template.php the following code (originally taken from includes/theme.inc):

<?php
/**
* Catch the theme_username function (see http://drupal.org/node/11811 )
*/
/**
 * Format a username.
 *
 * @param $object
 *   The user object to format, usually returned from user_load().
 * @return
 *   A string containing an HTML link to the user's page if the passed object
 *   suggests that this is a site user. Otherwise, only the username is returned.
 */
function phptemplate_username($object) {

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

    if (user_access('access user profiles')) {
      $output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
      $output = substr_replace($output, 'style="white-space: normal;" ', 3, 0);   //HS: allow line wrapping
    }
    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 ($object->homepage) {
      $output = l($object->name, $object->homepage);
    }
    else {
      $output = check_plain($object->name);
    }

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

  return $output;
}

?>

If the file is already there, then you may have to omit either or both of <?php and ?> in order to blend correctly into the context.