Question

I have been at this forever trying to find a solution and Im thinking either there isnt one or my lack of knowledge is really holding me back here.. In short I have buddypress installed on my Wordpress site and I have been using Simple Local Avatars for users to manage their avatars. Since I have been using this and have some customizations put into the simple local avatars plugin I would like to see if I can replace all the buddypress avatars with the local avatars.

In short my research has lead me to this: Buddypress uses bb_get_avatar function for display and management of its avatar, however the local avatars plugin uses the get_avatar function so after pulling my hair out, getting coffee and returning to just start pulling away at nothing I have come up with the below snippet in my functions.php file. It seems logical but is not working and again this is probably due to my noviceness but hey, I try..

This is what I have in functions.php:

//try the avatar thing
function socilize_custom_avatars() {
    global $bb_current_user;
    global $current_user;
    get_currentuserinfo();
    $avatar = bb_get_avatar( $bb_current_user->ID ); 

    unset($avatar); 
    $avatar = get_avatar($current_user->ID);

    return $avatar;
}

Seems (to me) like it should work but it doesnt, anyone able to chime in and tell me how to remove the buddypress avatars and have it pull the local avatars?

Thanks for reading :)

Was it helpful?

Solution

As you use BuddyPress you need to look at bp_core_fetch_avatar(). It's everywhere when BP installed. And in forums too.

You should use its filters, like bp_core_fetch_avatar and bp_core_fetch_avatar_url.

OTHER TIPS

there is the ultimate solution :

1 >> in wordpress setting set avatar to 'empty' or 'none' (sorry i have a french version of wordpress)

2 >> put that code in your function.php

// Kill gravatar

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() .'/images/customGravatar.png';

    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() .'/images/customGravatar.png';
    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() .'/images/customGravatar.png';

    if( $image && strpos( $image, "gravatar.com" ) ){ 

        return '<img src="' . $default . '" alt="avatar" class="avatar" width="auto" height="auto" />';
    } else {
        return $image;
    }

}
add_filter('bp_get_signup_avatar', 'bp_remove_signup_gravatar', 1, 1 );

3 >> change all the line '/images/customGravatar.png' with your own image

4 >> Now to allow users to upload there own local avatar add this plugin : Simple Local Avatars

That plugin add the capacity for user to add an avatar to there profil WORDPRESS // BUDDY PRESS hav already his own system of avatar replacement ;)

A possible, simpler solution..

add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

add to plugins/bp-custom.php

Originally answered and better explained here..

https://stackoverflow.com/a/34560419/3377049

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top