• So, here’s the problem I’m facing right now:
    I’m using WordPressp 3.0.1. I have modified my “Default” Gravatar in the admin dashboard. I have uploaded the default image that I would like to show in the comments section for those who don’t have a Gravatar yet.

    My question is now: how can I put a custom message under the default Gravatar?

    Because I would like to put a link to a “mini tutorial”, sort of a “Learn how to have a Gravatar” under the default Gravatar for those who don’t actually have a gravatar.

    If it helps, my custom Gravatar function is this:

    function customgravatar ($avatar_defaults) {
         $myavatar = get_bloginfo('template_directory') . '/images/custom-gravatar.jpg';
         $avatar_defaults[$myavatar] = "I.D. Protype Gravatars";
         return $avatar_defaults;
    }

    Please, I’d really appreciate it.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Have you read https://en.gravatar.com/site/implement/images/ ? It may help you using a hash and the d parameter to pull in a default image that has directions?

    Thread Starter ziont

    (@ziont)

    @ipstenu I would like to have my default gravatars untouched, I mean, with no directions and that kind of stuff. It would look nicer if I had a message under the picture.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    You can use the API to pull your own default. That said, I want to say you should be able to parse the output to customize an ‘error’ as well, but you’ll want to study on the API.

    Moderator keesiemeijer

    (@keesiemeijer)

    have you read: https://codex.www.ads-software.com/Using_Gravatars
    There is a function in there to check if there is an avatar:

    function validate_gravatar($email) {
    	// Craft a potential url and test its headers
    	$hash = md5($email);
    	$uri = 'https://www.gravatar.com/avatar/' . $hash . '?d=404';
    	$headers = @get_headers($uri);
    	if (!preg_match("|200|", $headers[0])) {
    		$has_valid_avatar = FALSE;
    	} else {
    		$has_valid_avatar = TRUE;
    	}
    	return $has_valid_avatar;
    }

    Thread Starter ziont

    (@ziont)

    Ok. I have copied the function above in my functions.php (thanks keesiemeijer) and here’s how I tried to validate and display a link for those who don’t have a Gravatar account while displaying my Default Gravatars:

    <?php if(function_exists('get_avatar')) {
     echo get_avatar($comment, '80');
    }
      if(function_exists('validate_gravatar')) {
      echo '<div style="margin-left: 20px;">
             <a href="myblogurl/miniturorial" title="How">(How?)</a>
             </div>';
    } ?>

    Except that it shows this custom link to all the users, both those who HAVE GRAVATARS and those WHO HAVEN’T.

    What else am I supposed to do display the link under the users who DON’T have a Gravatar account?

    Moderator keesiemeijer

    (@keesiemeijer)

    if you are in a comment loop like this :
    <?php foreach ($comments as $comment) : ?>
    You can check if the commenter has a valid gravatar like this:

    <?php
    if(validate_gravatar($comment->comment_author_email)){
    // has a valid gravatar
    } else {
    // has no gravatar
    }
    ?>

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    FYI, the reason yours didn’t work is becuase you did this:

    if(function_exists('validate_gravatar')) {
      echo '<div style="margin-left: 20px;">
             <a href="myblogurl/miniturorial" title="How">(How?)</a>
             </div>';

    That just says ‘If the function ‘validate_gravatar’ exists, then show ‘How to?” Which isn’t what you wanted ??

    Thread Starter ziont

    (@ziont)

    Got it. Here’s the final code:

    <?php if(function_exists('get_avatar')) {
       if(validate_gravatar($comment->comment_author_email)){
            echo get_avatar($comment, '80');
       }
       else {
            echo get_avatar($comment, '80');
            echo '<div style="margin-left: 20px;">
             <a href="https://yourblog/minitutorial" title="How">(How?)</a> </div>';
            }
    }
    ?>

    Thanks a lot, guys. Really appreciate your efforts. Thank you so much.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to detect if there's no Gravatar and pust a custom message under Gravatar??’ is closed to new replies.