I'm building Gravatar code for a theme for SEO reasons, basically don't like the default WordPress Gravatar code because for each avatar it adds an image to the page with no alt text which could have a negative SEO impact. Instead using the image as a background image with has no SEO impact.
Have the code working, but not with Mystery Man or Blank setting.
Looked at /wp-includes/pluggable.php and found the issue around line 1712 which is Mystery Man code, basically one Gravatar image is used (this image http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536) for all Mystery Men avatars except when the person has set a custom Gravatar. Similar idea with Blank.
Fixing Blank was easy enough, but what I've come up with so far means custom Gravatars (user selected ones) don't work when Mystery Man is selected. With the code below the default Mystery Man image is always used. I've looked through the WordPress Gravatar code and can't figure out how the custom Gravatars are selected?
<?php /*echo get_avatar($comment, 60);*/
$email = $comment->comment_author_email;
$size = 60;
$rating = get_option('avatar_rating');
$gravtype = get_option('avatar_default');
if ($gravtype=='mystery')
$grav_url = "http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=" . $size ."&d=" . $gravtype ."&r=". $rating;
elseif ($gravtype=='blank')
$grav_url = "/wp-includes/images/blank.gif";
else
$grav_url = "http://0.gravatar.com/avatar/" . md5($email) . "?s=" . $size ."&d=" . $gravtype ."&r=". $rating;
?>
<div class="gravatars" style="background: url(<?php echo $grav_url ?>)"></div>
Thanks
David
UPdate : Solved
Thanks to the suggestion from Bainternet using this code below which apears to work so far (not tested extensivly yet):
<?php /*echo get_avatar($comment, 60);*/
$email = $comment->comment_author_email;
$size = 60;
$rating = get_option('avatar_rating');
$gravtype = get_option('avatar_default');
$default = urlencode( 'http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size );
if ($gravtype=='mystery')
$grav_url = 'http://www.gravatar.com/avatar/'. md5( strtolower( trim( $email ) ) ). '?s=' . $size . '&r=' . $rating . '&d=' . $default;
elseif ($gravtype=='blank')
$grav_url = "/wp-includes/images/blank.gif";
else
$grav_url = "http://0.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?s=" . $size ."&d=" . $gravtype ."&r=". $rating;
?>
<div class="gravatars" style="background: url(<?php echo $grav_url ?>)"></div>
David