Completely disable the use of Gravatars on your BuddyPress site

Update: New versions of BuddyPress (1.7+) only need to add the following snippet to their bp-custom.php file

	add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

Gravatars are pretty darn great in general. But for certain communities there might be privacy reasons to disable them. BuddyPress let’s you do this, but it does not stop the calls being made to the Gravatar servers. This can sometimes lead to slower page loading times, and thus the people at BuddyPress.org came to the rescue! It took them a while to figure it out, but Scabadaska found a way to do it! Below is the complete code you need to put in functions.php or bp-custom.php. Enjoy!

function bp_remove_gravatar ($image, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir) {
	$default = get_stylesheet_directory_uri() .'/_inc/images/bp_default_avatar.jpg';
	if( $image && strpos( $image, "gravatar.com" ) ){
		return '<img src="' . $default . '" alt="avatar" class="avatar" ' . $html_width . $html_height . ' />';
	} else {
		return $image;
	}
}
add_filter('bp_core_fetch_avatar', 'bp_remove_gravatar', 1, 9 );
function remove_gravatar ($avatar, $id_or_email, $size, $default, $alt) {
	$default = get_stylesheet_directory_uri() .'/_inc/images/bp_default_avatar.jpg';
	return "<img alt='{$alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
}
add_filter('get_avatar', 'remove_gravatar', 1, 5);
function bp_remove_signup_gravatar ($image) {
	$default = get_stylesheet_directory_uri() .'/_inc/images/bp_default_avatar.jpg';
	if( $image && strpos( $image, "gravatar.com" ) ){
		return '<img src="' . $default . '" alt="avatar" class="avatar" width="150" height="150" />';
	} else {
		return $image;
	}
}
add_filter('bp_get_signup_avatar', 'bp_remove_signup_gravatar', 1, 1 );
BuddyPress Hosting Guide Looking for quality BuddyPress hosting? We will guide you through all the available hosting options and help you find the best webhost for your next BuddyPress project!

Something about bowe

BuddyPress fanatic, WordPress Theme designer and MultiSite community builder. Proud co-founder of PressCrew. Loves to use awesome in every sentence. Often described as a Dutch Treehugging Hippie.

10 Responses to Completely disable the use of Gravatars on your BuddyPress site

  1. Daniel May 6, 2011 at 4:09 pm #

    Very nice thanks ! Do you have also solution how to remove avatars only from activity stream ?

    • Daniel July 8, 2011 at 3:55 pm #

      Did you ever figure out how to remove the avatars from just the activity and comments etc?

      • Edit November 25, 2012 at 1:58 pm #

        The Gravatar solution has some merit, but it adds coxitemply to the initial sign up, which is already fairly technical. This raises barriers to broad acceptance of your service.

  2. nahum June 10, 2011 at 1:23 pm #

    I’m looking at this and I’m trying to think of a way to include a check to see if the user has entered the gender profile field and have 3 mystery default images depending on what was selected M/F/ or none and show the corresponding mystery avatar as default. Any Ideas.

  3. Mike Kennedy August 9, 2011 at 2:40 am #

    Will this work okay in BP 1.5?

  4. gwu August 13, 2011 at 12:55 am #

    can we use different images for users and groups?

  5. alis July 13, 2012 at 5:51 am #

    hi.
    i want to change gravatar to my avatar.
    tanks

  6. Jonas Lundman November 16, 2012 at 6:14 am #

    Thanks. Been crazy for month, and testing 20 plugins to get rid of that gravatar call in Buddypress. Now it works as I wanna! Yap!!

  7. ramon January 10, 2013 at 12:20 am #

    thanks you man, this works easy

  8. denisakinshin May 8, 2013 at 12:38 pm #

    Someone can tell why the code after making avatars disappeared, although in the path of such a file exists. Sorry for my english

Leave a Reply