Access $user object on comments I use the following snippet in template.php to access user profile fields on comment.tpl.php. $persianName works fine when the user is administrator, and returns nothing for the anonymous users. Actually, when I use dsm($variables) in anonymous viewing, I see that all UIDs are set to 0.

function apblog_preprocess_comment(&amp;$variables) {
  $user = $variables['user'];
  $user = user_load($user-&gt;uid);
  $persianName = field_get_items('user', $user, 'field_user_pname');
  if ($persianName) {
    $variables['persianName'] = $persianName[0]['safe_value'];
  }
  else {
    $variables['persianName'] ='';
  }

  // …
}
In drupal by default anonymous users have UID=0 , and you just need if $user->uid==0 set your variable to what you want , some string like "mehman" , 

because of doing little changes in your code I use inverse checking  of uid value ( the are as the same , 

if ( $user-&gt;uid ==0 )  $variables['persianName'] ='mehman';    


or   

if ( $user-&gt;uid !=0 ) ...... else  $variables['persianName'] ='mehman';


)    

function apblog_preprocess_comment(&amp;$variables) {
  $user = $variables['user'];
  $user = user_load($user-&gt;uid);
  $persianName = field_get_items('user', $user, 'field_user_pname');
  if ($user-&gt;uid !=0) {
    $variables['persianName'] = $persianName[0]['safe_value'];
  }
  else {
    $variables['persianName'] ='';
  }

  // …
}


I hope this work to you

be win ;)