[WP]WP-ReplaceGravatarMirror插件1.1版本发布
博客全面支持HTTPS协议访问后,之前做的WP-ReplaceGravatarMirror插件对HTTPS的访问效果不是太好,因此对
WP-ReplaceGravatarMirror插件进行了简单的一次小升级,让WP-ReplaceGravatarMirror同时支持HTTP和HTTPS网站,
本次改进只针对https网站进行优化,如果启用了HTTP访问的话欢迎下载和升级,没有启用HTTP访问且已经安装WP-ReplaceGravatarMirror1.0版本的可以不需要升级。
插件名称:WP-ReplaceGravatarMirror
插件说明:插件说明页面
当前版本:1.1
使用方法:
1.下载最新版本的WP-ReplaceGravatarMirror,解压已下载完成的文件。下载地址:https://github.com/limccn/WP-ReplaceGravatarMirror/tree/master/release/1.1
2.将解压后的wp-replace-gravatar-mirror文件夹上传到服务器的plugins目录下,或者使用Wordpress自带的上传安装插件功能
3.进入Wordpress后台,在插件选项卡中激活WP-ReplaceGravatarMirror
附上完整的WP-ReplaceGravatarMirror1.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; |
Recent Comments