最近发现博客的 Gravatar 头像显示不出来了,顺手做了个小插件,用于替换 WordPress 的默认头像服务。
if ( ! function_exists( 'get_mirror_avatar' ) ) {
function get_mirror_avatar( $avatar ) {
// 新 Gravatar 头像源,可自行修改
//$new_gravatar_sever = 'gravatar.loli.net/avatar/';
//$new_gravatar_sever = 'sdn.geekzu.org/avatar/';
//$new_gravatar_sever = 'gravatar.zunhuyun.com/avatar/';
$new_gravatar_sever = 'gravatar.kuibu.net/avatar/';
// 如果实在不行,就换cravatar.cn吧 文档:https://cravatar.com/developer/for-wordpress#more-53
$sources = array(
'www.gravatar.com/avatar/',
'0.gravatar.com/avatar/',
'1.gravatar.com/avatar/',
'2.gravatar.com/avatar/',
'secure.gravatar.com/avatar/',
'cn.gravatar.com/avatar/',
'gravatar.com/avatar/',
);
return str_replace( $sources, $new_gravatar_sever, $avatar );
}
add_filter( 'get_avatar', 'get_mirror_avatar' );
}