How to make gravatar.com avatars conditional?

Problem: I am using custom avatars for registered users and my own locally-hosted image as the default gravatar. I want to stop WordPress making HTTP requests to check for gravatar.com images on every comment.
Where my custom avatars are used, the scr result still includes a hashed link to gravatar.com with a redirect appended to the scr URI back to my own image.

Even without using a custom default avatar, there are two HTTP requests sent out.
For default avatars this looks like: http://1.gravatar.com/avatar/9cf9ecff0dd6eed9a1ea0948c61dc3c2?s=44&d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D44&r=G

I neither want, nor need, this kind of bloat in my pages.

Goal: What I want to do is to override the gravatars function in pluggable.php so that it only runs when a checkbox is checked. I have added a form field to my comments form so commenters can specify if they want to use their gravatar image from gravatar.com, their Twitter profile image, or (if left unchecked) if default, locally-hosted images apply. If the checkbox for gravatar.com avatars isn’t selected then it shouldn’t run at all.

I’m stuck on how to tie the get_avatar function to run only if the checkbox input returns true.

1 Answer
1

WordPress never makes any HTTP requests for gravatars, it just generates URLs to them.

You don’t really need to override function completely. You can filter get_avatar hook and return different URL if email matches user with custom avatar set.

Leave a Comment