webCOMAND

User::get_initials()

Get the closest thing to a user's initials for a User based on which fields are defined.

This is helpful for producing the letter(s) that appear in a User's profile icon.

Prototype

string get_initials()

Return

A string based on the defined fields with the following preference:

  1. If a First Name and Last Name is defined, use the first letter from each.
  2. If only a First Name is defined, return the first letter.
  3. If only a Last Name is defined, return the first letter.
  4. If none of the above are defined, but a Username is defined, return the first letter.
  5. If none of the above are defined, but an Email is defined, return it the first letter.
  6. If none of the above are defined, return a question mark ("?").

Example

$users = $repo->get("FROM User WHERE Email!=''");
foreach($users as $user) {
	echo($user->get_initials() . "\n" );
}

Related

get_full_name()