All my gravatars look the same
stephencarr - July 7, 2009 - 21:46
| Project: | Gravatar integration |
| Version: | 6.x-1.7 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed |
Jump to:
Description
Every gravatar in my comments looks just the same. I was under the impression from using gravatars in Wordpress that each commenter would get a unique gravatar. Not sure if I have done something wrong or if something is just broken.

#1
What kind of default gravatar image option do you have selected? Only the Identicon, Wavatar and MonsterId options are uniquely generated for users that don't have a Gravatar.
#2
Sorry, I should clarify I am testing with MonsterId against anonymous user comments. I can see that registered users get unique gravatars, or a gravatar associated with their email address.
#3
Most likely then, your anonymous user comments don't have an email, so a blank string is used. If you edit one of the comments you should be able to see if an e-mail address was entered. You can also force users to enter in their e-mail address by enabling the "Anonymous posters must leave their contact information" option on http://example.com/admin/content/node-type/story (or whichever content type you use).
#4
Ah, yes you are right! But I took a look at the code and see that from the $variables array you can extract 'hostname' which is the commenter's IP address and I think this could be used as an alternate fallback hash seed for anonymous users who do not provide an email address.
If you could tell me how to get 'hostname' from that array I could implement it myself. So far I have tried
$variables['account']->hostname;But this is always empty, which is odd because $variables['account']->mail; supposedly carries the email address string from the same array.
#5
It appears that when a comment is loaded for display, the hostname column is not included in the SQL query, so we cannot make any use of it in the Gravatar module.
#6
My php is really rusty so I might be wrong, but when I put a print_r($variables); in gravatar.module gravatar_preprocess_user_picture() I get the array spitting out and including 'hostname' with the correct value. I am probably wrong but I just assumed if I can echo out that full array from the gravatar.module it must have access to the full array.
#7
The $variables['user']->hostname is for the current user (you) not the comment. We can't use that information. The information about the commenter is in $variables['account'].
#8
OK, it's probably no big deal to most but this is how I got round this, it might help others who want individual gravatars for anons who don't want to leave any email address:
Find:
// Load mail/homepage variable from an anonymous comment.
if (empty($account->mail) && !empty($variables['account']->mail)) {
$account->mail = $variables['account']->mail;
}
if (empty($account->homepage) && !empty($variables['account']->homepage)) {
$account->homepage = $variables['account']->homepage;
}
And replace it with
// Load mail/homepage variable from an anonymous comment.
if (empty($account->mail) && !empty($variables['account']->mail)) {
$account->mail = $variables['account']->mail;
} elseif (empty($account->mail)){
$account->mail = $variables['account']->name;
}
if (empty($account->homepage) && !empty($variables['account']->homepage)) {
$account->homepage = $variables['account']->homepage;
}
It hashes on the name they provide which for me is as good a fall back as I think I am going to get.
#9
I submitted a patch for Drupal core to provide the hostname field in comments so it can be used by Gravatar. I'm doubtful that it will be backported to Drupal 6, but at least it can be used when Gravatar is ported to Drupal 7.
EDIT: Forgot the link to the issue: #514928: Provide {comment}.hostname in comment_render()
#10
Until this can be fixed in Drupal core, I'm marking this as postponed.