Home > 博客技巧, 语言编程 > [WP]WP-ReplaceGravatarMirror插件

[WP]WP-ReplaceGravatarMirror插件

最近,伟大的中华神墙再次发威,屏蔽掉了Wordpress等博客系统广泛使用的Gravatar头像系统,Wordpress在大陆使用时会出现Gravatar无法加载而导致的异常缓慢,好在国内的duoshuo.com提供了国内使用的Gravatar镜像系统,目前来说通行使用正常,于是花了一点时间写了一个Wordpress可以使用的插件,可以解决由于GFW屏蔽导致的Gravatar头像无法加载和加载缓慢的问题,在此分享给大家,欢迎下载使用。

插件名称:WP-ReplaceGravatarMirror
插件说明:插件说明页面
使用方法:
1.下载最新版本的WP-ReplaceGravatarMirror,解压已下载完成的文件。下载地址:https://github.com/limccn/WP-ReplaceGravatarMirror/tree/master/release/1.0
2.将解压后的wp-replace-gravatar-mirror文件夹上传到服务器的plugins目录下,或者使用Wordpress自带的上传安装插件功能
3.进入Wordpress后台,在插件选项卡中激活WP-ReplaceGravatarMirror

/**
 * Plugin Name: WP-ReplaceGravatarMirror
 * Plugin URI:  https://github.com/limccn/WP-ReplaceGravatarMirror
 * Description: This plugin can helps your wordpress blog replace its default gravatar provider(gravatar.com) to a third-part gravatar mirror(duoshuo.com) which can be load faster in somewhere.
 * Author:      limc
 * Author URI:  http://www.lidaren.com/
 * Version:     1.0
 * License:     GPL 2.0
 */
 
/**
 * Silence is golden
 */
if (!defined('ABSPATH')) exit;
 
class WP_Replace_Gravatar_Mirror
{
 
    /**
     * init Hook
     *
     */
    public function __construct()
    {
        add_filter('get_avatar', array($this,'replace_gravatar_to_duoshuo'), 10, 3);
    }
 
 
    /**
     * Use DuoShuo's gravatar mirror to replace Gravatar's.
     * Simplely replace from "*.gravatar.com" to "gravatar.duoshuo.com".
     *
     * @param $avatar
     * @return mixed
     */
    public function replace_gravatar_to_duoshuo($avatar)
    {
        $avatar = str_replace(array('www.gravatar.com','0.gravatar.com','1.gravatar.com','2.gravatar.com','s.gravatar.com'),'gravatar.duoshuo.com',$avatar);
        return $avatar;
    }
}
 
/**
 * bootstrap
 */
new WP_Replace_Gravatar_Mirror;


插件的源代码可以在github找到,GitHub地址:https://github.com/limccn/WP-ReplaceGravatarMirror

最后,感谢多说网(duoshuo.com)提供的Gravatar镜像服务

  1. October 27th, 2015 at 12:52 | #1

    真的很不错,问题解决了!

    顺便吐槽一下GFW

  2. 李大仁
    October 27th, 2015 at 15:54 | #2

    @TranchBellic WP-ReplaceGravatarMirror插件1.1版本已经发布,请到https://github.com/limccn/WP-ReplaceGravatarMirror/tree/master/release/1.1下载

  3. May 3rd, 2016 at 12:31 | #3

    不错,学习了,嘿嘿

  1. No trackbacks yet.
You must be logged in to post a comment.