Original link: https://yunfanch.com/website/1953.html
Cravatar is perfectly compatible with all Gravatar avatar API interfaces. At the same time, if you do not set an avatar in Cravatar, it will first try to call the avatar data on Gravatar, followed by the QQ avatar, and finally return a set of default avatars that we have prepared for you. For blog sites, on average, this results in an accurate profile picture for 70% of visitors.
Integrate for Typecho
Just add the following code to config.inc.php in the root directory of the site:
/** * 替换Gravatar头像为Cravatar头像* * Cravatar是Gravatar在中国的完美替代方案,你可以在https://cravatar.cn更新你的头像*/ define('__TYPECHO_GRAVATAR_PREFIX__', 'https://cravatar.cn/avatar/');
Integrate for WordPress
You can easily integrate the Cravatar avatar service for WordPress, just add the following code to the functions.php of your plugin or theme:
if ( ! function_exists( 'get_cravatar_url' ) ) { /** * 替换Gravatar 头像为Cravatar 头像* * Cravatar 是Gravatar 在中国的完美替代方案,你可以在https://cravatar.cn 更新你的头像*/ function get_cravatar_url( $url ) { $sources = array( 'www.gravatar.com', '0.gravatar.com', '1.gravatar.com', '2.gravatar.com', 'secure.gravatar.com', 'cn.gravatar.com', 'gravatar.com', ); return str_replace( $sources, 'cravatar.cn', $url ); } add_filter( 'um_user_avatar_url_filter', 'get_cravatar_url', 1 ); add_filter( 'bp_gravatar_url', 'get_cravatar_url', 1 ); add_filter( 'get_avatar_url', 'get_cravatar_url', 1 ); } if ( ! function_exists( 'set_defaults_for_cravatar' ) ) { /** * 替换WordPress 讨论设置中的默认头像*/ function set_defaults_for_cravatar( $avatar_defaults ) { $avatar_defaults['gravatar_default'] = 'Cravatar 标志'; return $avatar_defaults; } add_filter( 'avatar_defaults', 'set_defaults_for_cravatar', 1 ); } if ( ! function_exists( 'set_user_profile_picture_for_cravatar' ) ) { /** * 替换个人资料卡中的头像上传地址*/ function set_user_profile_picture_for_cravatar() { return '<a href="https://cravatar.cn" target="_blank">您可以在Cravatar 修改您的资料图片</a>'; } add_filter( 'user_profile_picture_description', 'set_user_profile_picture_for_cravatar', 1 ); }
This article is reprinted from: https://yunfanch.com/website/1953.html
This site is for inclusion only, and the copyright belongs to the original author.