Php 在Wordpress评论中显示Google个人资料图像。如果作者是gmail.com,则为gravatar

Php 在Wordpress评论中显示Google个人资料图像。如果作者是gmail.com,则为gravatar,php,wordpress,google-plus,avatar,gravatar,Php,Wordpress,Google Plus,Avatar,Gravatar,我想显示评论作者谷歌个人资料图片,如果他输入了gmail.com的电子邮件地址,否则我会在评论中显示gravatar 由于我在编码方面的局限性,我设法将示例代码进一步构建: function comment_image() { $email = get_avatar(get_comment_author_email()); $domains = array('gmail.com', 'google.com'); $pattern = "/^[a-z0-9._%+-]+@[a-z0-9.-]*

我想显示评论作者谷歌个人资料图片,如果他输入了gmail.com的电子邮件地址,否则我会在评论中显示gravatar

由于我在编码方面的局限性,我设法将示例代码进一步构建:

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);
}
我将在我的评论模板中调用上述函数以显示图像:

<?php echo comments_image(); ?>


提前感谢这个伟大的社区。

如果您的问题纯粹是语法问题,这应该会有帮助:

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
 }

你好像把大括号放错地方了#是的,我同意以上不是一个正确的代码,我不是一个程序员。需要帮助输入正确的代码和函数。感谢以上内容。您能否帮助使用
功能email\u to\u userid($email)
。如果邮件ID是Gmail,需要获取个人资料图像。@I'm国王不能为你做家庭作业。让我看看你到目前为止都做了些什么!