Add the user picture before the username in user listings? I'm trying to add the user picture before the username in user listings. I've copied theme_username into my template.php and I'm trying to call theme with the argument 'user_picture' in order to get the HTML that will render the picture, but the call just returns an empty string. I'm providing the uid as the argument. Where am I going wrong?
Thanks.

function MY-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';

    // I ADDED THIS LINE

    $output = theme('user_picture', array('account' =&gt; $variables['account']));

    // ENDS

    $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 = '&lt;span' . drupal_attributes($variables['attributes_array']) . '&gt;' . $variables['name'] . $variables['extra'] . '&lt;/span&gt;';
  }
  return $output;
}
theme_user_picture is not a Drupal 7 function, whereas in the example you provide you are using Drupal 7's theme_username function code. Moreover, even in Drupal 6, theme_user_picture returns nothing because in that version of Drupal it's merely a placeholder and the actual themeing of the user entry is handled via the corresponding template file user-picture.tpl.php. This is possibly the reason your theme call returns nothing. Please refer to api.drupal.org to find the correct implementation for your Drupal version.

So, assuming that you are on Drupal 7, note that $variables['account'] is not a fully populated user object and does not contain any reference to the user picture. You need to actually load the user object and give the picture some themeing in order to show it in your listing. Your code could be something like this:

function MY-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';

    // I ADDED THIS LINE

    //$output = theme('user_picture', array('account' =&gt; $variables['account']));
    $user = user_load($variables['account']-&gt;uid);
    if (isset($user-&gt;picture-&gt;uri)) {
      $output = theme('image_style', array('path' =&gt; $user-&gt;picture-&gt;uri,'style_name' =&gt; 'thumbnail'));
    }
    // ENDS

    $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 = '&lt;span' . drupal_attributes($variables['attributes_array']) . '&gt;' . $variables['name'] . $variables['extra'] . '&lt;/span&gt;';
  }
  return $output;
}