| 5 theme.inc | theme_username($object) |
| 6 theme.inc | theme_username( |
| 7 theme.inc | theme_username($variables) |
| 8 user.module | theme_username($variables) |
Returns HTML for a username, potentially linked to the user's page.
Parameters
$variables: An associative array containing:
- account: The user object to format.
- name: The user's name, sanitized.
- extra: Additional text to append to the user's name, sanitized.
- link_path: The path or URL of the user's profile page, home page, or other desired page to link to for more information about the user.
- link_options: An array of options to pass to the l() function's $options parameter if linking the user's name to the user's page.
- attributes_array: An array of attributes to pass to the drupal_attributes() function if not linking to the user's page.
See also
template_preprocess_username()
Related topics
23 theme calls to theme_username()
File
- includes/
theme.inc, line 2123 - The theme system, which controls the output of Drupal.
Code
function theme_username($variables) {
if (isset($variables['link_path'])) {
// We have a link path, so we should generate a link using l().
// Additional classes may be added as array elements like
// $variables['link_options']['attributes']['class'][] = 'myclass';
$output = l($variables['name'] . $variables['extra'], $variables['link_path'], $variables['link_options']);
}
else {
// Modules may have added important attributes so they must be included
// in the output. Additional classes may be added as array elements like
// $variables['attributes_array']['class'][] = 'myclass';
$output = '<span' . drupal_attributes($variables['attributes_array']) . '>' . $variables['name'] . $variables['extra'] . '</span>';
}
return $output;
}
Login or register to post comments
Comments
This print the current logged
This print the current logged in user's with link:
<?phpglobal $user;
print t('!username logged in', array('!username' => theme('username', array('account' => $user)))),
?>
$variables['name'] and $variables['extra'] do not work
Setting values into $variables['name'] or $variables['extra'] (array('name' => ..., 'extra' => ...) ) won't work under the default implementation, due to template_preprocess_username(). It has code:
$variables['extra'] = '';...
$name = $variables['name_raw'] = format_username($account);
...
$variables['name'] = check_plain($name);
This code overrides anything set in $variables['name'] and $variables['extra'].
The only ways I can see to put in a custom name would be to either
None of these options are ideal.
Edit: $variables['link_path'] is also overridden.
If you just want custom
If you just want custom output then you need to override this function in your theme. I tried overriding the theme_username function and it works as expected.
Please refer http://drupal.org/node/173880 for more information.
My point is that, if using
My point is that, if using the theme_username's default implementation does not respect the values sent in the associative array. If I have
<?phptheme('username', array('name' => 'Custom Name'));
?>
Use hook_username_alter()
To change the default display of your user account, change it with hook_username_alter