banner
李大仁博客

李大仁博客

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

[WP] WP-ReplaceGravatarMirror插件1.1版本发布

After the blog fully supports HTTPS protocol access, the previous WP-ReplaceGravatarMirror plugin did not work well for HTTPS access. Therefore, a simple minor upgrade was made to the WP-ReplaceGravatarMirror plugin to support both HTTP and HTTPS websites. This improvement only optimizes for HTTPS websites. If you have enabled HTTP access, you are welcome to download and upgrade. If you have not enabled HTTP access and have already installed WP-ReplaceGravatarMirror version 1.0, you do not need to upgrade.

Plugin Name: WP-ReplaceGravatarMirror
Plugin Description: Plugin description page
Current Version: 1.1
Usage:

  1. Download the latest version of WP-ReplaceGravatarMirror and unzip the downloaded file. Download link: https://github.com/limccn/WP-ReplaceGravatarMirror/tree/master/release/1.1
  2. Upload the extracted wp-replace-gravatar-mirror folder to the plugins directory on the server, or use the built-in upload and install plugin function of Wordpress.
  3. Go to the Wordpress backend and activate WP-ReplaceGravatarMirror in the plugins tab.

Attached is the complete source code of WP-ReplaceGravatarMirror 1.1.

/**
* 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\]+)&.\*/','![](https://secure.gravatar.com/avatar/$1?s=$2)',$avatar);

    return $avatar;
}

}
/**
* bootstrap
*/
new WP_Replace_Gravatar_Mirror;

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。