Reputation: 2907
I want to remove gravatar link from wordpress admin but I want to keep the profile picture. How to do this?
Upvotes: 0
Views: 981
Reputation: 886
If you want to replace the gravatar-based avatar link with default avatars in local, you can add the following code fragment to your functions.php
in your theme.
function replace_gravatar_with_default_local_avatar() {
return some_url_to_default_avatar_image;
}
add_filter( 'pre_option_avatar_default', 'replace_gravatar_with_default_local_avatar' );
And if you actually want sort of cache
or the gravatar, you can establish a cache logic, and use the get_avatar
hook to handle this. Here is an example of cache logic.
function cache_gravatar($avatar) {
$tmp = strpos($avatar, 'http');
$g = substr($avatar, $tmp, strpos($avatar, "'", $tmp) - $tmp);
$tmp = strpos($g, 'avatar/') + 7;
$f = substr($g, $tmp, strpos($g, "?", $tmp) - $tmp);
$w = get_bloginfo('wpurl');
$e = ABSPATH .'avatar/'. $f .'.png';
$t = dopt('d_avatarDate')*24*60*60;
if ( !is_file($e) || (time() - filemtime($e)) > $t )
copy(htmlspecialchars_decode($g), $e);
else
$avatar = strtr($avatar, array($g => $w.'/avatar/'.$f.'.png'));
if ( filesize($e) < 500 )
copy(get_bloginfo('template_directory').'/img/default.png', $e);
$avatar = preg_replace("/srcset='([^']*)'/", '', $avatar);
return $avatar;
}
add_filter('get_avatar','cache_gravatar');
Upvotes: 1