Adding support for Gravatars through our user class is as easy as adding a few lines of code. After that, we'll add the gravatar
function all over our application.
1. Open
user/profile.php
and apublic
function calledgravatar
that accepts a parameter called size; we'll give it a default value of50
.public function gravatar($size='50') { }
2. In order to get the users' Gravatar, we just need to create an
md5
hash of a user's e-mail address, which will serve as thegravatar_id
. We'll then set the size using our$size
variable, and append all of that to Gravatar's web service URL.public function gravatar($size='50') { return 'http://www.gravatar.com/avatar/?gravatar_id=' .md5(strtolower($this->email)).'&size='.$size; }
3. That's it! We now have Gravatar support in our application. We just need to start adding it anywhere we want to see a profile image. Let's start by adding a large Gravatar into the User Information section at...