theKing
theKing

Reputation: 844

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:

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 - [email protected]
        //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.

Upvotes: 2

Views: 1011

Answers (1)

docksteaderluke
docksteaderluke

Reputation: 2245

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 - [email protected]
  // 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
 }

Upvotes: 0

Related Questions