Same name and namespace in other branches
  1. 5.x includes/theme.inc \theme_username()
  2. 6.x includes/theme.inc \theme_username()
  3. 7.x includes/theme.inc \theme_username()

Format a username.

Parameters

$object: The user object to format, usually returned from user_load().

Return value

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.

Related topics

21 theme calls to theme_username()
chameleon_comment in themes/chameleon/chameleon.theme
chameleon_node in themes/chameleon/chameleon.theme
comment_admin_overview in modules/comment.module
Menu callback; present an administrative comment listing.
node_admin_nodes in modules/node.module
Menu callback: content administration.
node_revision_overview in modules/node.module
Generate an overview table of older revisions of a node.

... See full list

File

includes/theme.inc, line 957
The theme system, which controls the output of Drupal.

Code

function theme_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) > 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(
        '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 ($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;
}