Hot answers tagged gravatar
3
Basic setup
<?php
$args = array( 'orderby' => 'nicename' );
$users = get_users( $args );
foreach ( $users as $user ) {
$avatar = get_avatar( $user->ID, '80' );
echo '<li><a href="' .
$user->user_url .
'">' .
$avatar . '<br />' .
...
3
You can use get_avatar. The following example prints an avatar in 96 px, assuming that you have the user id stored in $user_id, and prints a fallback user.png if no such user or image could be found.
echo get_avatar($user_id, 96, get_stylesheet_directory_uri() . '/images/user.png');
2
From Gravatar.com:
All URLs on Gravatar are based on the use of the hashed value of an email address (link)
Instead of storing an email adress in the comment data, you can store the md5-hash of that email adress. The email adress is encrypted and you can use gravatars. Use the filter add_filter( 'preprocess_comment', 'email_to_md5' ) to modify the ...
1
I think that i figured it out.
Gravatar default images need to be on a public url and not one blocked by htaccess. So i had this on my dev server and when i removed my htaccess file that was blocking access the images started to work. This seems to still be a new feature. Hope that this helps out someone in the future.
1
Here's a simple example showing default avatars and lists all users with the role of author.
foreach ( get_users( array( 'role' => 'author' ) ) as $user )
{
echo get_avatar(
$user->ID
,'96'
,get_stylesheet_directory_uri().'/default-avatar.png'
,$user->nice_name
);
}
1
As informed by @Rarst, apparently currently Gravatar only accepts one value for size. It is really unfortunate. However I managed to work-around this by facilitating timthumb.php and a function I found from here: How to get gravatar url alone
I'm not sure if this is the best way to do this (it looks messy), however this works for me for creating 60x40 px ...
1
<?php
add_filter(
'get_avatar',
'get_avatar_url',
10,
5
);
function get_avatar_url( $avatar, $id_or_email, $size = 96, $default = '', $alt = '' ) {
preg_match( '#src=["|\'](.+)["|\']#Uuis', $avatar, $matches );
return ( isset( $matches[1] ) && ! empty( $matches[1]) ) ?
(string) $matches[1] : '';
}
Apply a ...
1
It's fairly simple to construct the Gravatar URL yourself, it's just an MD5 hash of the user's email address.
<?php $gravatar = 'http://www.gravatar.com/avatar/' . md5(strtolower($email)) . '&s=32'; ?>
<div class="avatar" style="background: url(<?php echo $gravatar ?>);" ></div>
The s parameter at the end there defines the ...
Only top voted, non community-wiki answers of a minimum length are eligible