function hook_username_alter

hook_username_alter(&$name, $account)

Alter the username that is displayed for a user.

Called by format_username() to allow modules to alter the username that's displayed. Can be used to ensure user privacy in situations where $account->name is too revealing.

Parameters

$name: The string that format_username() will return.

$account: The account object passed to format_username().

See also

format_username()

Related topics

File

modules/system/system.api.php, line 4368
Hooks provided by Drupal core and the System module.

Code

function hook_username_alter(&$name, $account) {
  // Display the user's uid instead of name.
  if (isset($account->uid)) {
    $name = t('User !uid', array('!uid' => $account->uid));
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_username_alter/7.x