Custom avatar function

Hello I work on WordPress and I have a premium theme which is not supported from the creator anymore so I am trying to make a change; I am not sure that this is called a bug. On comments when a visitor is place a comment; his avatar is not the default ‘mystery’ in this case (no_avatar.gif) but it automatically takes the avatar of the current post author. I like to shows the default for unregistered users. I would like to notice that the theme is use it’s own avatars. I target the code on functions but I am not able to change it, any help would be appreciated, thanks in advance here is the code:

function tgt_get_avatar_link($user_id = ""){
if (!empty($user_id)){
    $avatar = get_the_author_meta('tgt_image', $user_id);
}
else
$avatar = get_the_author_meta('tgt_image');
if (!$avatar){
    return TEMPLATE_URL . '/images/no_avatar.gif';
}
    return TEMPLATE_URL . $avatar;
}

Update: The function is calling tgt_get_avatar_link but it seems that is:

Read More
function tgt_ad_comment($comment, $args, $depth){
    $GLOBALS['comment'] = $comment;
    global $helper;
    ?>
    <li>
    <div class="comment" id="comment-<?php comment_ID()?>">
        <?php //echo get_avatar($comment) ?>
        <?php echo $helper->image(tgt_get_avatar_link($comment->user_id), $comment->comment_author, array('title' => $comment->comment_author, 'width' => '58px', 'height' => '58px'))  ?>
        <div class="comment_content">
            <strong><?php echo get_comment_author_link() ?></strong> <?php _e('Say ','ad')?>(<?php comment_time('F j, Y at g:i a') ?>)
            <br/>
            <?php comment_text() ?>
        </div>

</div>

The function is calling $user_id but it seems that is:

function tgt_get_avatar_link($user_id = ""){
   if (!empty($user_id)){
    $avatar = get_the_author_meta('tgt_image', $user_id);
}
   else
    $avatar = get_the_author_meta('tgt_image'); 
   if (!$avatar){
    return TEMPLATE_URL . '/images/no_avatar.gif';
   }
   return TEMPLATE_URL . $avatar;   
}

Related posts

Leave a Reply

1 comment

  1. If the comment author has no defined avatar, you’d like to show a default image. This seems to be the else in your conditional:

    else { $avatar = get_the_author_meta('tgt_image'); }
    

    Without a $user_id to pass to get_the_author_meta, it assumes the user ID of the current post author. This is likely causing the behavior you describe.

    Try to remove the else statement, skipping straight from if (!empty($user_id)){$avatar = get_the_author_meta('tgt_image', $user_id);} to if (!$avatar){.... Now, when the function is passed a null user_id, it should return TEMPLATE_URL . '/images/no_avatar.gif';