我想显示评论作者google个人资料图片,如果他输入了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(); ?>
提前感谢这个伟大的社区。 p>
答案 0 :(得分:0)
如果你的问题纯粹是语法问题,那么这应该会有所帮助:
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
}