Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have tried everything to override the BP Avatar. Found about 5-6 different Google results that basically all point to the same solution:

function override_bp_member_avatar($url) {
    return get_stylesheet_directory_uri() . '/default_avatar.png';
}
add_filter('bp_core_fetch_avatar_no_grav', '__return_true'); // http://codex.buddypress.org/extending-buddypress/tips-tricks/
add_filter('bp_core_mysteryman_src', 'override_bp_member_avatar'); // http://www.buddyboss.com/instructions/

Yet it does not work.

Has anyone had success using a default Avatar for members?

share|improve this question

closed as off-topic by Pieter Goosen, birgire, toscho Aug 4 at 20:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

    
The Simple Facebook Connect plugin replaces avatars with Facebook profile pictures. You might check out that plugin, specifically the sfc-login.php file to see how it's being done. –  developdaly Apr 16 '12 at 21:21

1 Answer 1

up vote 2 down vote accepted

The filters you cite are only for the default/fallback avatars. If you want to replace BP avatars altogether, the key filters are bp_core_fetch_avatar and bp_core_fetch_avatar_url. The latter filters the entire HTML avatar element, while the latter does just the URL.

How you do the filtering depends on how fancy you want to get. The bp_core_fetch_avatar passes along a lot of useful parameters, if you want to totally rebuild the avatar HTML: https://buddypress.trac.wordpress.org/browser/tags/1.5.5/bp-core/bp-core-avatars.php#L297 Otherwise, for a quick fix, you could just preg_replace() the URL.

/**
 * This function returns your new avatar URL. You can put whatever logic in here you want
 */
function wpse_49216_my_new_avatar_url() {
    return 'http://example.com/avatar.jpg';
}
add_filter( 'bp_core_fetch_avatar_url', 'wpse_49216_my_new_avatar_url' );

function wpse_49216_filter_bp_avatar( $html ) {
    return preg_replace( '/src=".+?"/', 'src="' . wpse_49216_my_new_avatar_url() . '"', $html );
}
add_filter( 'bp_core_fetch_avatar', 'wpse_49216_filter_bp_avatar' );

EDIT: The above method will replace all avatars. If you only want to change the default/fallback avatar (for users who have not uploaded their own), try

/**
 * Disable Gravatar throughout BP
 */
add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );

/**
 * Provide a global user avatar default
 */
function wpse_49216_my_new_default_avatar_url() {
    return 'http://example.com/avatar.jpg';
}
add_filter( 'bp_core_default_avatar_user', 'wpse_49216_my_new_default_avatar_url' );
share|improve this answer
    
Thanks @BooneGorges. It got me closer, but it ended up replacing all avatars including the ones that current members uploaded themselves. What I need to do is allow members to upload their own picture as their avatar. However, if someone does not do that, I don't want to use gravatars. I want to use one (1) default avatar that I have stored as get_stylesheet_directory_uri() . '/default_avatar_blue.png'. Is that possible to do? –  H. Ferrence Apr 17 '12 at 11:36
1  
Here's how I got around the matter: I added add_filter('bp_core_fetch_avatar_no_grav', '__return_true'); to my functions.php file in my theme directory. Then I physically replaced ../wp-content/plugins/buddypress/bp-core/images/mystery-man.jpg with the standard avatar I want. <more...> –  H. Ferrence Apr 17 '12 at 11:51
    
I am not a fan of overwriting or tweaking core files (including images) because someone else on staff here may come along and update/upgrade our WP install and blow away my "hard-coded" tweak. Then they may not know how to recover form it (although I have included extensive documentation of my customizations to the install), but I cannot guarantee others will read my doc. –  H. Ferrence Apr 17 '12 at 11:52
    
Yes, it is possible. When you first said "I have tried everything to override the BP Avatar" I figured you wanted to override all avatars. I have edited my answer with a proper method. As you note, it's a bad idea to change the core files, and in this case there are several filters there that make it unnecessary to do so. –  Boone Gorges Apr 17 '12 at 12:29
    
Got it. Thanks @BooneGorges –  H. Ferrence Apr 17 '12 at 13:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.