Home > 博客技巧 > [WP]WP-ReplaceGravatarMirror插件1.1版本发布

[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源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?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;
  1. No comments yet.
  1. No trackbacks yet.