什么是 Cravatar 头像?

“Avatar” 是指代表您在线身份的图像,也就是当您在与网站互动时,在您的名字旁边显示的小图片。
“Cravatar” 是中国认可的头像(China Recognized Avatar)的缩写。您只需上传一张图像并创建您的公共个人资料,然后当您参与任何支持 Cravatar 的网站时,您的 Cravatar 图像和公共个人资料将自动跟随您。
Cravatar 是免费的服务,面向网站所有者、开发者和用户。它已经自动包含在每个 Weixiaoduo.com 账户中,并由文派开源运营和支持。
重要内容 ▼ ▼ ▼
{cat_hide}
▶Cravatar官网:https://cravatar.com/
▶注册并且上传头像
{/cat_hide}

使用Cravatar

Typecho使用Cravatar

将以下代码加入到根目录的Typecho配置文件config.inc.php中即可


define('__TYPECHO_GRAVATAR_PREFIX__', 'https://cravatar.cn/avatar/'); //更换头像源
WordPress使用Cravatar

只要在主题的functions.php中加入以下代码即可

if ( ! function_exists( 'get_cravatar_url' ) ) {
    /**
     * 替换 Gravatar 头像为 Cravatar 头像
     */
    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 );
}

标签: typecho, 教程, wordpress

已有 20 条评论

  1. 看看行不😷

  2. 谢谢分享😀

  3. Ai飞客 Ai飞客

    来看看大佬的教程

  4. 云溪 云溪

    问你一下大佬 一样的主题 为啥我的是加密的 想改东西都改不了

  5. 我来瞅一瞅🧐

  6. 看解决方案

  7. 大佬快来指导一下😀

  8. 戒说 戒说

    Typecho使用Cravatar
    将以下代码加入到根目录的Typecho配置文件config.inc.php中即可
    找不到这个咋整

    1. 就在根目录下

      1. 就找到了
        ban.js
        functions.php
        index.php
        这三个

        1. 慢慢找,总会看见的

  9. 戒说 戒说

    😏😏😏说说说说

  10. 猫

    ?????

  11. 哦哦ohhhh 哦哦ohhhh

    ?????????

  12. Winn Winn

    不错的文章?

  13. aia aia

    不错学习了。?

  14. yoyo yoyo

    不错学习了。?

  15. 先收藏,备用。???

  16. 不错学习了。?

添加新评论