banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

[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 鏡像服務

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。