[resolved] get_avatar() Problems (8 posts)

I'm working on a theme and am using the get_avatar function. The WordPress docs on this site state,

"If the gravatar reverts to the default image, whether you have specified a default or not, the img element will also be given a class of avatar-default"

Unfortunately, no such class is being assigned to my gravatars when the default image is displayed. Here's my code...quite simple, which is why I can't figure out what the problem is...echo get_avatar($comment, '80');

Thanks but that's not what my problem is. The avatar appears just fine, that's not my problem. My problem is that, when the default avatar appears, there is, according to WordPress.org, supposed to be an "avatar-default" class assigned to the default avatar image, but that class is not being assigned to any default avatar images.

Maybe if I clarify my reasoning, it will help. I'm going to hide the avatar image completely if it's a default image using display: none; and was planning on applying that style to the "avatar-default" class so that whenever a default avatar image is returned from the get_avatar() function, the image is simply hidden instead of actually displaying a default image.

Just in case anyone was going to suggest it, I did consider using a transparent gif for the default image, but I don't want the comment text to wrap around the transparent gif as if there was an image there.

So, in summary, if I can get this done another way, that'd be just fine (but no plugins because I'm doing this for a theme design):

All I need is to be able to hide the avatar image completely if the commentator does not have a Gravatar.

Forgot to mention...I'm proficient with php but for the life of me cannot find the location of the get_avatar function. If I can find that function I can probably figure out how to do what I'm trying to do...either that or I'll just write a new one. Anyone know where that function is? I've checked functions.php and didn't find it there.

Take a look @ /wp-includes/pluggable.php and i think you 'll find what you are after but have in mind that if you "touch" the core files then you 'll have to remember it in the next upgrade. IMHO best way is to write a small plugin for it since you can handle PHP.

Ok, I got it figured out. It seems to be a bug in WP 2.5.1. I've submitted a bug report. The "avatar-default" class is not being assigned when the default avatar is used. I've added the following to line 1257 in pluggable.php in the get_avatar function and it's solved the problem.

What I'd like to do is actually go a little further than that. Instead of loading an image and then hiding it with CSS, I'd like to not call the image at all if there isn't an avatar for the person posting a comment. Reduces the number of calls to gravatar.com :) I haven't played with this yet, but will do so in the next couple days, maybe I can figure it out :) I'll report if I do.