Skip to main content
3 of 4
added 653 characters in body
xLRDxREVENGEx
  • 1.2k
  • 1
  • 15
  • 24

get_user_meta Short Profile Section

Ok so i have added a custom field into the users edit profile page where they can add a link to a url of an image they want. I am currently using this for contribitors and above but i also have a small little profile box on my site that gets a users avatar from gravatar. I used the code from before but changed it around to get the current signed on users authorpic or get the gravatar. See code below

$profilepic = get_user_meta('author_pic');
$imgtagbeg = ('<img style="height:52px; width:52px" src="');
$imgtagend = ('"/>');
    if ($profilepic)
        echo $imgtagbeg,$profilepic,$imgtagend; 
    else
        echo get_avatar( $user_email, '52', $default = 'http://www.gravatar.com/avatar.php?gravatar_id=$md5&size=80&default=$default' );

What i want to do is if the current user signed in has a avatar linked in his profile field then use that instead of gravatar. But if the author does have a gravatar and has left the field blank in the profile use that or get the default gravatar

Update: What about something like this

$userpic = '<img src="link/to/author_pics/$userid.png"';
    if ($userpic)
        echo $userpic;
    else
        echo get_avatar( $user_email, '52', $default = 'http://www.gravatar.com/avatar.php?gravatar_id=$md5&size=80&default=$default' );

Instead of relying on a user field just upload an image to a directory and use there userid as the filename then load it else use gravatar. Would that work.

UPDATE 2:

$userpiccur = wp_get_current_user();
$userpicloc = 'http://avatars.mydomain.com/';
$userpictyp = '.png';
$userpicurl = $userpicloc . $userpiccur->user_login . $userpictyp;
$header_response = get_headers($userpicurl, 1);
$userpicbeg = '<img style="height:52px; width:52px" src="http://avatars.mydomain.com/';
$userpicend = '.png"/>';
if ( strpos( $header_response[0], "404" ) !== false )
    echo $userpicbeg,$user_login->user_login,$userpicend;
else
    echo get_avatar( $user_email, '52', $default = 'http://www.gravatar.com/avatar.php?gravatar_id=$md5&size=80&default=$default' );
xLRDxREVENGEx
  • 1.2k
  • 1
  • 15
  • 24