Name Update Time
Netflix September 14, 2024 10:30 am
Disney+ September 10, 2024 10:09 am
Max September 14, 2024 10:20 am
ChatGPT 4 September 14, 2024 2:26 pm
Spotify September 14, 2024 2:08 pm
Prime Video September 14, 2024 2:22 pm
Codecademy September 14, 2024 2:13 pm
Grammarly September 14, 2024 4:45 pm
Canva Pro September 12, 2024 2:24 pm
Udemy Premium Cookies September 2, 2024 2:53 pm

In order to improve the user experience, I thought of caching the commenter’s avatar locally. Most of the avatar files are in png format. I tried to delete all cached avatars and re-cache them. After refreshing, the avatars can be displayed normally. The following is the cached avatar code:

function fa_cache_avatar($avatar, $id_or_email, $size, $default, $alt)
{
$avatar = str_replace(array(“www.gravatar.com”, “0.gravatar.com”, “1.gravatar.com”, “2.gravatar.com”), “cn.gravatar.com”, $avatar);
$tmp = strpos($avatar, ‘http’);
$url = get_avatar_url( $id_or_email, $size ) ;
$url = str_replace(array(“www.gravatar.com”, “0.gravatar.com”, “1.gravatar.com”, “2.gravatar.com”), “cn.gravatar.com”, $url);
$avatar2x = get_avatar_url( $id_or_email, ( $size * 2 ) ) ;
$avatar2x = str_replace(array(“www.gravatar.com”, “0.gravatar.com”, “1.gravatar.com”, “2.gravatar.com”), “cn.gravatar.com”, $avatar2x);
$g = substr($avatar, $tmp, strpos($avatar, “‘”, $tmp) – $tmp);
$tmp = strpos($g, ‘avatar/’) + 7;
$f = substr($g, $tmp, strpos($g, “?”, $tmp) – $tmp);
$w = home_url();
$e = ABSPATH .’avatar/’. $size . ‘*’. $f .’.jpg’;
$e2x = ABSPATH .’avatar/’. ( $size * 2 ) . ‘*’. $f .’.jpg’;
$t = 1209600;
if ( (!is_file($e) || (time() – filemtime($e)) > $t) && (!is_file($e2x) || (time() – filemtime($e2x)) > $t ) ) {
copy(htmlspecialchars_decode($g), $e);
copy(htmlspecialchars_decode($avatar2x), $e2x);
} else { $avatar = $w.’/avatar/’. $size . ‘*’.$f.’.jpg’;
$avatar2x = $w.’/avatar/’. ( $size * 2) . ‘*’.$f.’.jpg’;
if (filesize($e) < 1000) copy($w.’/avatar/default.jpg’, $e);
if (filesize($e2x) < 1000) copy($w.’/avatar/default.jpg’, $e2x);
$avatar = “{$alt}”;
}
return $avatar;
}
add_filter(‘get_avatar’, ‘fa_cache_avatar’,1,5);