Gravatar 代理
一个简单的Gravatar头像代理,可用于WordPress
如何使用
将WordPress中的默认Gravatar URL替换为您的域名加上API端点:
https://gp.hunya.net/api/gravatar?hash=%HASH%&s=%SIZE%&d=%DEFAULT%&r=%RATING%✓ 服务器端缓存已启用
此代理使用服务器端缓存来减少对Gravatar的请求并提高性能。
参数
- hash: 电子邮件地址的MD5哈希值
- s: 头像大小(默认:80)
- d: 当电子邮件哈希不存在时使用的默认图像(默认:mp)
- r: 头像评级(默认:g)
WordPress集成
将以下代码添加到您的主题的functions.php文件中:
add_filter('get_avatar_url', 'custom_gravatar_url', 10, 3);
function custom_gravatar_url($url, $id_or_email, $args) {
$email_hash = '';
// Get email hash
if (is_numeric($id_or_email)) {
$user = get_userdata($id_or_email);
if ($user) {
$email_hash = md5(strtolower(trim($user->user_email)));
}
} elseif (is_object($id_or_email)) {
if (!empty($id_or_email->user_id)) {
$user = get_userdata($id_or_email->user_id);
if ($user) {
$email_hash = md5(strtolower(trim($user->user_email)));
}
} elseif (!empty($id_or_email->comment_author_email)) {
$email_hash = md5(strtolower(trim($id_or_email->comment_author_email)));
}
} else {
$email_hash = md5(strtolower(trim($id_or_email)));
}
// Build custom Gravatar URL
$size = isset($args['size']) ? $args['size'] : 80;
$default = isset($args['default']) ? $args['default'] : 'mp';
$rating = isset($args['rating']) ? $args['rating'] : 'g';
return 'https://gp.hunya.net/api/gravatar?hash=' . $email_hash . '&s=' . $size . '&d=' . $default . '&r=' . $rating;
}自动检测到的域名
当前使用的域名: https://gp.hunya.net
系统会自动使用您访问时的域名,无需手动配置。
部署您自己的Gravatar代理
一键部署到Vercel或查看源代码
想要部署您自己的Gravatar代理?只需点击下面的按钮,即可将此项目部署到您的Vercel账户:
部署后,您可能需要添加以下集成以获得最佳性能:
- Vercel KV - 用于服务器端缓存