Show Google profile image in WordPress comments. if author is gmail.com else gravatar

I would like to show comments author google profile picture, if he entered a gmail.com email address, else I will show the gravatar in comments.

With my limitation in coding I managed to put sample code to construct further:

Read More
function comment_image() {
$email = get_avatar(get_comment_author_email());

$domains = array('gmail.com', 'google.com');

$pattern = "/^[a-z0-9._%+-]+@[a-z0-9.-]*(" . implode('|', $domains) . ")$/i";

if (preg_match($pattern, $email)) {

    function email_to_userid() {
        // get user id of the email address - xyz@gmail.com
        //request google profile image url eg: https://www.googleapis.com/plus/v1/people/123456789?fields=image&key={API_KEY}
        // above will retun URL:  "url": "https://lh3.googleusercontent.com/-abcdef/bbbbbas/photo.jpg?sz=50"
        // return the image URL
    }
}
   } elseif; {
   echo get_avatar($comment, 60);
}

I will call the above function in my comments template to show the image:

<?php echo comments_image(); ?>

Thanks in advance for this great community.

Related posts

1 comment

  1. If you problem is purely syntactical, this should help:

    function comments_image() {
      $email = get_avatar(get_comment_author_email());
    
      $domains = array('gmail.com', 'google.com');
    
      $pattern = "/^[a-z0-9._%+-]+@[a-z0-9.-]*(" . implode('|', $domains) . ")$/i";
      if (preg_match($pattern, $email)) {
        email_to_userid($email);
      } elseif {
        echo get_avatar($comment, 60);
      }
    }
    
    function email_to_userid($email) {
      // get user id of the email address - xyz@gmail.com
      // request google profile image url eg: https://www.googleapis.com/plus/v1/people/123456789?fields=image&key={API_KEY}
      // above will retun URL:  "url": "https://lh3.googleusercontent.com/-abcdef/bbbbbas/photo.jpg?sz=50"
      // return the image URL
     }
    

Comments are closed.