我想显示评论作者谷歌个人资料图片,如果他输入了一个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 - [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);
}
字符串
我将在我的评论模板中调用上面的函数来显示图像:
<?php echo comments_image(); ?>
型
提前感谢这个伟大的社区。
1条答案
按热度按时间yyhrrdl81#
如果你的问题是纯粹的语法,这应该会有所帮助:
字符串