Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
fix: 修复头像替换逻辑错误
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed May 3, 2023
1 parent b89abd0 commit 938e295
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions inc/service/class-super.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,22 @@ public function __construct() {
if ( $setting->get_option( 'weavatar', 'wp_china_plus_setting', 'on' ) != 'off' ) {
add_filter( 'user_profile_picture_description', [ $this, 'set_user_profile_picture_for_weavatar' ], 1 );
add_filter( 'avatar_defaults', [ $this, 'set_defaults_for_weavatar' ], 1 );
add_filter( 'um_user_avatar_url_filter', [ $this, 'get_weavatar_url' ], 1 );
add_filter( 'bp_gravatar_url', [ $this, 'get_weavatar_url' ], 1 );
add_filter( 'get_avatar_url', [ $this, 'get_weavatar_url' ], 1 );

if ( $setting->get_option( 'weavatar', 'wp_china_plus_setting', 'on' ) != 'cc' ) {
add_filter( 'um_user_avatar_url_filter', [ $this, 'get_weavatar_com_url' ], 1 );
add_filter( 'bp_gravatar_url', [ $this, 'get_weavatar_com_url' ], 1 );
add_filter( 'get_avatar_url', [ $this, 'get_weavatar_com_url' ], 1 );
add_filter( 'um_user_avatar_url_filter', [ $this, 'get_weavatar_com_url' ], PHP_INT_MAX );
add_filter( 'bp_gravatar_url', [ $this, 'get_weavatar_com_url' ], PHP_INT_MAX );
add_filter( 'get_avatar_url', [ $this, 'get_weavatar_com_url' ], PHP_INT_MAX );
} else {
add_filter( 'um_user_avatar_url_filter', [ $this, 'get_weavatar_cc_url' ], 1 );
add_filter( 'bp_gravatar_url', [ $this, 'get_weavatar_cc_url' ], 1 );
add_filter( 'get_avatar_url', [ $this, 'get_weavatar_cc_url' ], 1 );
add_filter( 'um_user_avatar_url_filter', [ $this, 'get_weavatar_cc_url' ], PHP_INT_MAX );
add_filter( 'bp_gravatar_url', [ $this, 'get_weavatar_cc_url' ], PHP_INT_MAX );
add_filter( 'get_avatar_url', [ $this, 'get_weavatar_cc_url' ], PHP_INT_MAX );
}
}

/**
Expand All @@ -140,9 +153,9 @@ public function __construct() {
}

/**
* 头像替换函数
* 头像替换函数(com域名)
*/
function get_weavatar_url( $url ) {
function get_weavatar_com_url( $url ) {
$sources = array(
'www.gravatar.com',
'0.gravatar.com',
Expand All @@ -155,13 +168,31 @@ function get_weavatar_url( $url ) {
'gravatar.duoshuo.com',
'gravatar.loli.net',
'cravatar.cn',
'weavatar.cc',
);

if ( $setting->get_option( 'weavatar', 'wp_china_plus_setting', 'on' ) != 'cc' ) {
return str_replace( $sources, 'weavatar.com', $url );
} else {
return str_replace( $sources, 'weavatar.cc', $url );
}
return str_replace( $sources, 'weavatar.com', $url );
}

/**
* 头像替换函数(cc域名)
*/
function get_weavatar_cc_url( $url ) {
$sources = array(
'www.gravatar.com',
'0.gravatar.com',
'1.gravatar.com',
'2.gravatar.com',
'secure.gravatar.com',
'cn.gravatar.com',
'gravatar.com',
'sdn.geekzu.org',
'gravatar.duoshuo.com',
'gravatar.loli.net',
'weavatar.com',
);

return str_replace( $sources, 'weavatar.cc', $url );
}

/**
Expand Down

0 comments on commit 938e295

Please sign in to comment.