Skip to content

Instantly share code, notes, and snippets.

Created July 21, 2017 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/551f22507b7edf2be1b70d4c5a9f86c9 to your computer and use it in GitHub Desktop.
Save anonymous/551f22507b7edf2be1b70d4c5a9f86c9 to your computer and use it in GitHub Desktop.
add_filter('get_avatar_url', 'wpse_avatar_or_gravatar', 10, 3);
function wpse_avatar_or_gravatar($url, $email, $args) {
// Manually edit the /wp-admin/includes/class-wp-users-list-table.php (439) and /wp-includes/admin-bar.php to show avatar using email
$path = sprintf('/home/asdasd/public_html/wp-content/images/users/%s.jpg',
md5(strtolower(trim($email . "scripto")))
);
$url = sprintf('%s/images/users/%s.jpg',
"//www.asd.com/wp-content",
md5(strtolower(trim($email . "scripto")))
);
if (file_exists($path)) {
// image exists, return url
$url = sprintf('//www.asd.com/wp-content/images/users/%s.jpg',
md5(strtolower(trim($email . "scripto")))
);
}
else {
// image does not exist, return default avatar
$url = "https://0.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?s=64&d=identicon&f=y&r=g";
}
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment