
Wouldn’t it be great if the box above could be automatically filled by your Gravatar profile?

Tons of services auto-populate your info using Gravatar right? Why can’t my profile information (and social media info) just auto populate in WordPress too!? (NOTE: someone smarter than me should definitely work on getting this into WordPress core!)
Thankfully, it’s just a matter of tapping into the Gravatar API. Yup, there is a full fledged API with support for JSON, XML, PHP, VCF, and QR codes which makes it super easy to grab data.
A real world problem
Recently, a client was interested in adding an Author Box to each post. They run a large multi-site network (with over 100 authors) and asking the authors to fill out their bio on both Gravatar AND the WordPress dashboard (thus, repeating themselves) was out of the question.
The authors were asked to fill out their information once (on Gravatar) and I handled bringing in the data via the API.
A real solution
I built a function that gets the post author’s info using the Gravatar API.
[snippet slug=get-authors-gravatar-profile-data lang=php]
This above function returns an array of data:
[snippet slug=gravatar-api lang=php]
This particular client is using Genesis, so I hooked into the Author Box filter, looped through the array, and extracted the data:
[snippet slug=do-author-box lang=php]
The final product, an author box with profile information from Gravatar’s API:

Pretty easy, huh? Now stop repeating yourself, and start using the Gravatar API!
(The above code can be forked from this Github Gist)
Great article! One suggestion I have is to pull json since typically json_decode is faster than unserialize. It’s also much safer to decode json in the crazy event someone hacks Gravatar and pushes malicious code out.