WP-ReplaceGravatarMirror

September 2nd, 2015 Leave a comment Go to comments

About WP-ReplaceGravatarMirror

WP-ReplaceGravatarMirror 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.

Project in GitHub.

关于WP-ReplaceGravatarMirror

WP-ReplaceGravatarMirror通过将国内已屏蔽的gravatar.com的头像服务器替换到国内可以访问和使用的duoshuo.com上实现在中国大陆访问Wordpress博客时gravatar头像可以使用的功能。

托管在GitHub的项目地址.

Installation

  1. Download the latest version of WP-ReplaceGravatarMirror plugin package and decompress it.
  2. Upload wp-replace-gravatar-mirror folder to the /wp-content/plugins/ directory.
  3. Activate the plugin through the ‘Plugins’ menu in WordPress
    1. 安装

      1. 下载最新版本的WP-ReplaceGravatarMirror插件安装包,并在下载完成后解压。
      2. 将解压文件中的wp-replace-gravatar-mirror目录上传到/wp-content/plugins/目录下
      3. 在WordPress后台激活并启用WP-ReplaceGravatarMirror插件

      History, Change Logs

      v1.0, 2015-07-14 The first stable version released.

      v1.1, 2015-09-01 supports both http:// add https://.

      License

      WP-ReplaceGravatarMirror is released under the GPL 2.0.

      Source Code

      Version 1.1

      <?php
       
      /**
       * 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.1
       * License:     GPL 2.0
       */
       
      /**
       * Silence is golden
       */
      if (!defined('ABSPATH')) exit;
       
      class WP_Replace_Gravatar_Mirror
      {
       
          /**
           * init Hook
           *
           */
          public function __construct()
          {
              if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
              {
                  add_filter('get_avatar', array($this,'replace_gravatar_to_ssl'), 10, 3);
              }else
              {
                  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;
          }
       
          /**
           * Use https gravatar server to replace none-https.
           * Simplely replace from "http://*.gravatar.com" to "https://secure.gravatar.com".
           *
           * @param $avatar
           * @return mixed
           */
          public function replace_gravatar_to_ssl($avatar)
          {
              $avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img src="https://secure.gravatar.com/avatar/$1?s=$2" class="avatar avatar-$2" height="$2" width="$2">',$avatar);
       
              return $avatar;
          }
      }
      /**
       * bootstrap
       */
      new WP_Replace_Gravatar_Mirror;

      Version 1.0

      /**
       * 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;
  1. July 17th, 2015 at 21:21 | #1

    不错,过来支持一下!

  2. August 21st, 2015 at 08:37 | #2

    不错,过来学习了

  3. September 2nd, 2015 at 22:02 | #3

    已经升级!

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