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; 
        echo get_avatar( $user_email, '52', $default = '$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

What about something like this

$userpic = '<img src="link/to/author_pics/$userid.png"';
    if ($userpic)
        echo $userpic;
        echo get_avatar( $user_email, '52', $default = '$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.


$userpiccur = wp_get_current_user();
$userpicloc = '';
$userpictyp = '.png';
$userpicurl = $userpicloc . $userpiccur->user_login . $userpictyp;
$header_response = get_headers($userpicurl, 1);
$userpicbeg = '<img style="height:52px; width:52px" src="';
$userpicend = '.png"/>';
if ( strpos( $header_response[0], "404" ) !== false )
    echo $userpicbeg,$userpiccur->user_login,$userpicend;
    echo get_avatar( $user_email, '52', $default = '$md5&size=80&default=$default' );

Solutions Collecting From Web of "get_user_meta Short Profile Section"

From the core:

function get_user_meta($user_id, $key, $single = false) {
    return get_metadata('user', $user_id, $key, $single);

Pass the user id as the first argument, the key 'author_pic' as the second and TRUE as the third (to get a string value back).

Your code in the edit part of the question should work, and also your first part but you need to add the user ID to get_user_meta() function so use your first code but change the first line to this:

$profilepic = get_user_meta($user_id,'author_pic',true);

and make sure $user_id hold the user’s actual ID.

Ok so i got it working like i want. Now all i have to do is figure out if i want a user to be able to upload there own image or not.

$userpiccur = wp_get_current_user();
$userpicloc = '';
$userpictyp = '.png';
$userpicurl = $userpicloc.$userpiccur->user_login.$userpictyp;
$userpicbeg = '<img class="avatar avatar-52 photo" style="height:52px; width:52px" src="';
$userpicend = '"/>';
if (@fopen($userpicurl, "r"))
    echo  $userpicbeg,$userpicurl,$userpicend;
    echo get_avatar( $user_email, '52', $default = '$md5&size=80&default=$default' );