/ Published in: PHP
I pinched the get_avatar() function from the wp/wp-includes/pluggable.php file and commented out the setting of the avatar as an tag and returned the actual image url instead.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function get_avatar_url($id_or_email, $size = '96', $default = '', $alt = false) { if (! get_option('show_avatars')) { return false; } if (false === $alt) { $safe_alt = ''; } else { $safe_alt = esc_attr($alt); } $email = ''; $id = (int) $id_or_email; $user = get_userdata($id); if ($user) { $email = $user->user_email; } } // No avatar for pingbacks or trackbacks $id = (int) $id_or_email->user_id; $user = get_userdata($id); if ($user) { $email = $user->user_email; } } elseif ( !empty($id_or_email->comment_author_email) ) { $email = $id_or_email->comment_author_email; } } else { $email = $id_or_email; } $avatar_default = get_option('avatar_default'); else { $default = $avatar_default; } } if (is_ssl()) { $host = 'https://secure.gravatar.com'; } else { else { $host = 'http://0.gravatar.com'; } } if ('mystery' == $default) { $default = "$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]') } elseif ('blank' == $default) { $default = includes_url('images/blank.gif'); } elseif ('gravatar_default' == $default) { $default = "$host/avatar/s={$size}"; } $out = "$host/avatar/"; $out .= $email_hash; $out .= '?s='.$size; $rating = get_option('avatar_rating'); //$avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />"; $avatar = $out; } else { //$avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />"; $avatar = $default; } return $avatar; }