@jmichaelward I like the idea. In talking it over with @joemcgill, we were wonderin what would happen if someone supplies a non-square image size? If I recall correctly (and it has not changed), I believe Gravatar will only return a square. Say the image size is 800x400. The image returned could return unexpected results.

@desrosj That's a good question. I can't believe it's been almost a year since I first submitted this - let me take a look at my submitted patch and investigate what happens with non-square image sizes and see if I can address it adequately.

@desrosj So, first, a little background on this ticket: I was working on some updates for a plugin developed by my last employer that allows users to upload a custom user profile photo. We had written a custom method that users would call to output that image, and I'd felt that seemed unnecessary when we can simply filter get_avatar inside of our plugin, and instruct them to use the native WordPress method inside of their themes (which also means they will not receive fatal errors when deactivating the plugin, should they have called the method without a function_exists check).

With regard to Gravatar's square imagery, it appears that I had accounted for the square imagery returned by the service. In the patch, if a user requests a non-square WordPress image size (e.g., medium, large, or something custom), get_avatar will check if the requested size is registered, get the register image size's dimensions, then set the size to the greater of height or width.

I see now that this solution is half-baked. The user may not be expecting a square image, and they may not be expecting the larger of the two dimensions to be used. I do see that get_avatar sets some defaults for height and width, so your recommendation for pre_get_avatar may already address this.

In my view, a call to get_avatar should:

Allow the user to retrieve an image from non-Gravatar services (for example, the WordPress media library)

Allow them to have a non-square profile image

I'm going to play around with this code some more and see if I can address this using pre_get_avatar, per your recommendation, and then also check whether it's possible to support passing a string for the image size as my previous patch does.

After some further consideration, I think it may be acceptable to allow a user to pass a registered WordPress image size and have it revert to a square Gravatar image if pre_get_avatar is not filtered, so long as we document what developers can expect in this case. This latest patch will set the size of the Gravatar image to the height of the registered WordPress image size (squared) in the event that pre_get_avatar is not filtered.

These changes will allow developers to filter pre_get_avatar to return non-square avatars using native WordPress registered image sizes. It accounts for custom image sizes as well, so if a theme registers its own avatar thumbnail, the developers can call <?php get_avatar( $user_id, 'my-custom-avatar-thumbnail' ); ?> and expect to get the correct registered image size.

Additional unit tests are needed, but I think this is on the right path.