Changing Drupal username for profile_name

Today while setting up the blog i decided that i would prefer having Real Name showing instead of User Name.

So, after reading some helpful posts and documentation i decided to get hands on.

Steps:
  • Activate Profile Module
  • Create custom field profile_name or whatever, just don't forget to change it in the code accordingly
  • Change theme template.php to override phptemplate_username
References: http://api.drupal.org/api/function/theme_username/6 http://drupal.org/node/21110
//sumarize username
function sumarize_text($text, $max, $crop) {
	if (drupal_strlen($text) > $max) { 
  	$text = drupal_substr($text, 0, $crop) .'...';
	}
	return $text;
}


#override theme_username
function phptemplate_username($object) { 
	//check for profile_name field - Profile module
	if (!$object->profile_name) {
		//check for existence of profile_load_profile function
		if ( $object->uid && function_exists('profile_load_profile') ) {
			//load it
			profile_load_profile($object); 
		}
	}
	
	//check if user exists
  if ($object->uid && $object->name) {
		//check for profile_name for this user
		if ($object->profile_name) {
    	// Shorten the name when it is too long or it will break many tables. 
    	$name = sumarize_text($object->profile_name, 20, 15);
    }
		else {
			//fallback to username
			$name = sumarize_text($object->name, 20, 15);
		}

    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', t('Anonymous')); 
  } 

  return $output; 
}

All should be working as intended!

Taxonomy upgrade extras: