Provides a variety of official and user-released code examples. For code reference, you are welcome to exchange and learn that the wordpress Avatar system has always been using the Global Avatar gravatar. I want to use this avatar system in my project. After reviewing wordpress, you can simply modify it to get the gravatar function get_avatar_src you want. This function returns the required Avatar address. Some functions have not yet been implemented. You can change them as needed ....
/**
* Return the avatar address of the user.
*
* @ Param unknown $ id_or_email
* User ID or email address
* @ Param string $ size
* Size
* @ Param string $ default
* Default Avatar
* @ Param string $ alt
* @ Return string
*/
Function get_avatar_src ($ id_or_email, $ size = '96 ', $ default = ''){
If (! Is_numeric ($ size ))
$ Size = '96 ';
$ Email = '';
If (is_numeric ($ id_or_email )){
// Process id Input
} Else {
// Otherwise, send $ email
$ Email = $ id_or_email;
}
// Default Avatar
If (empty ($ default )){
$ Avatar_default = ''; // get_option ('Avatar _ default'); // obtain the default settings
If (empty ($ avatar_default) // if no value is set, the default value is defined.
$ Default = 'mystery ';
Else
$ Default = $ avatar_default;
}
If (! Empty ($ email) // generates the hash code if it is not empty.
$ Email_hash = md5 (strtolower (trim ($ email )));
If (! Empty ($ email) {// If the email address is not empty, use the email address to generate a link.
$ Host = sprintf ("http: // % d.gravatar.com", (hexdec ($ email_hash) % 2 ));
} Else // otherwise use the default address
$ Host = 'HTTP: // 0.gravatar.com ';
$ Host = str_replace (array (
"Www.gravatar.com ",
"0.gravatar.com ",
"1.gravatar.com ",
"2.gravatar.com"
), "Gravatar.duoshuo.com", $ host );
If ('mystery' = $ default)
$ Default = "$ host/avatar/ad516503a11cd5ca435acc9bb6523536? S = {$ size} "; // ad516503a11cd5ca435acc9bb6523536 = md5 ('unknown @ gravatar.com ')
Elseif ('blank '= $ default)
// If it is empty (blank), the blank image is obtained.
$ Default = $ email? 'Blank ': ''; // includes_url ('images/blance.gif ');
Elseif (! Empty ($ email) & 'gravatar _ default' = $ default)
// If the mailbox already exists, clear the default Avatar
$ Default = '';
Elseif ('gravatar _ default' = $ default)
$ Default = "$ host/avatar /? S = {$ size }";
Elseif (empty ($ email ))
$ Default = "$ host/avatar /? D = $ default & s = {$ size }";
If (! Empty ($ email )){
$ Out = "$ host/avatar /";
$ Out. = $ email_hash;
$ Out. = '? S = '. $ size;
$ Out. = '& d ='. urlencode ($ default );
$ Out = str_replace ('&', '&', strip_whitespace ($ out ));
} Else {
$ Out = $ default;
}
Return $ out;
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB