Where should I place on which page this code?
function my_cache_avatar_url() {
update_user_meta( bp_displayed_user_id(), 'modemloopers_awesome_avatar_url', bp_core_fetch_avatar( 'html=false&item_id=' . bp_displayed_user_id() ) );
}
add_action( 'xprofile_screen_change_avatar', 'my_cache_avatar_url' );
You can disable Gravatar like this:
function no_grav() {
return true;
}
add_filter( 'bp_core_fetch_avatar_no_grav', 'no_grav' );
Hi @shanebp,
Sorry for the confusion, I’ve created a bp_group_list_managers that’s a merge of bp_group_list_admins and bp_group_list_mods to provide a single consolidated listing.
function bp_group_list_managers($group=false) {
global $groups_template;
if(empty($group)) {
$group =& $groups_template->group;
}
// fetch group admins if 'populate_extras' flag is false
if (empty($group->args['populate_extras']) || true) {
$query = new BP_Group_Member_Query(array(
'group_id' => $group->id,
'group_role' => 'admin',
'type' => 'alphabetical',
));
if (!empty($query->results)) {
$group->admins = $query->results;
}
}
// fetch group mods if 'populate_extras' flag is false
if (empty($group->args['populate_extras']) || true) {
$query = new BP_Group_Member_Query(array(
'group_id' => $group->id,
'group_role' => 'mod',
'type' => 'alphabetical',
));
if (!empty($query->results)) {
$group->mods = $query->results;
}
}
$admins = (array)$group->admins;
$mods = (array)$group->mods;
usort($admins, 'bp_group_member_sort');
usort($mods, 'bp_group_member_sort');
$group->managers = array_merge($admins, $mods);
if (!empty($group->managers)) { ?>
<ul id="group-managers">
<?php foreach((array)$group->managers as $manager) { ?>
<li>
<a href="<?php echo bp_core_get_user_domain($manager->user_id, $manager->user_nicename, $manager->user_login); ?>"><?php echo bp_core_fetch_avatar(array('item_id' => $manager->user_id, 'email' => $manager->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname($manager->user_id)))) ?></a>
</li>
<?php } ?>
</ul>
<?php } else { ?>
<span class="activity"><?php _e( 'No Managers', 'buddypress' ) ?></span>
<?php }
}
As you can see I set the type here to alphabetical and was first confused why it did nothing then I realized the BP_Group_Member_Query’s were never even called as I guess populate_extras was set so not empty. This meant that the $group->admins and $group->mods came from the global $group_template->group which wasn’t ordered. I’m curious how to make that global $group_template->group admin/mod lists could be alphabetically ordered by default.
For now I just amended my method to simply force the BP_Group_Member_Query’s to be used instead which has allowed for the alphabetical ordering.
Hope that clears things up.
Thanks
That’s a tricky one. And I don’t have a solution.
It’s probably a timing issue. The hook fires before the dir is updated.
Or maybe bp_core_fetch_avatar is cached.
Which version of BP are you using?
The issue may be related to the new approach to avatar uploads using the BP_Attachments class.
Hi,
I have one problem with fetching avatars using bp_core_fetch_avatar() function and xprofile_avatar_uploaded action. I keep my avatars as user meta. What I want to do is to update that meta every time new avatar is uploaded from back end. I wrote this functions:
function update_avatar_admin(){
update_user_meta(bp_displayed_user_id(),'profile_photo',bp_core_fetch_avatar( array( 'item_id' => bp_displayed_user_id(), 'html' => false ) ));
}
add_action('xprofile_avatar_uploaded', 'update_avatar_admin', 99);
The thing is it always gets previous avatar and not the one uploaded.
The sql call isn’t returning the user ID.
Change the sql to:
$usernames = $wpdb->get_results("SELECT ID, user_nicename FROM $wpdb->users ORDER BY ID DESC LIMIT 5");
Then make this change:
$recentusers .= '<li>' . bp_core_fetch_avatar( array( 'item_id' => $username->ID, 'type' => 'full') ) . '<a href="' . bp_core_get_user_domain($username->ID) .'">' . $username->user_nicename . '</a></li>';
Thanks for the explanation @danbp. Ahhhh the Mystery Man ha.
WP is using get_avatar and BP substitute it with his own code for internal purpose.
So if i understand you, WP calls for the user’s Gravatar regardless via get_avatar and Buddypress then just takes it from WP to make it appear on the user profile? Therefore the code add_filter('bp_core_fetch_avatar_no_grav', '__return_true'); only stops the second part of the process where Buddypress requests the user’s Gravatar from WP. That right?
Deactivating Gravatar will also deprive the people who use the service to get their usual picture on your site. It’s not an innocent decision.
Yeah I agree. The reasons I have now for wanting to prevent access to Gravatar is for data/privacy/3rd party website reasons and also slowdown (if the user numbers did reach certain levels). I don’t want to ‘force’ them to upload a profile pic because I want them to give as little or as much to their profile as they feel like (which is why I wouldn’t use the Buddydev force profile pic plugin either).
Thanks @henrywright! I’ll stick with add_filter('bp_core_fetch_avatar_no_grav', '__return_true'); then if it’s all I need to stop the Buddypress calls. What is it that WordPress calls for? Are you referring to the default ‘white figure on grey background’? Or does WordPress also check for a Gravatar in similar way to Buddypress. (I don’t currently use Gravatar).
Hi @djsteveb , I came across some of those posts you listed which is actually what got me thinking about it in the first place :). I’m trying to be as transparent as possible on user privacy/data on the site I’m creating. Searched the forums a little further and some of the threads are v old so thought I’d check if the stuff there was still applicable or had been deprecated.
Hi @danbp, thanks for the plugin suggestions. I’ve come across a few Buddydev plugins and will probably use their ‘bp-activity-comment-notifier’ plugin since they aren’t part of Buddypress default currently. Trying to keep plugins to a minimum early on.
With regards to the ‘bp-avatar-suggestions’ plugin (which you appear to have inspired), does that override any WordPress calls Henry mentioned above since you are using your own locally stored images? (similar I guess to the new user Twitter eggs)?
Hi all,
Want to totally remove the use of Gravatars and calls to external servers for them (user privacy/data reasons etc). Also want to encourage users to upload photo themselves.
Just want to know if the code below is still applicable or is it outdated (published in 2011):
https://bp-tricks.com/snippets/completely-disable-the-use-of-gravatars-on-your-buddypress-site/
I have tried sticking it in bp_custom file but there is an unexpected ; somewhere in the first function which produces an error.
If the above is outdated will this suffice (or are calls still made to 3rd party servers):
add_filter('bp_core_fetch_avatar_no_grav', '__return_true');
Thanks
WP 4.2
BP 2.2.3.1
Previous snippet changed all avatars (user, blogs and groups) which is not what you want. Here’s a snippet which works almost correctly, but not to 100%. Give it a try anyway.
It changes the user avatar depending of an xprofile value.
(add to bp-custom.php)
function bpfr_my_new_avatar_url() {
global $bp;
if( bp_is_user() && ! bp_get_member_user_id() ) {
$user_id = bp_displayed_user_id();
} else {
$user_id = bp_get_member_user_id();
}
if ( is_page( 'activity' ) ) {
$user_id = bp_get_activity_user_id();
}
$ranking = xprofile_get_field_data ('ranking', $user_id );
if ($ranking == "Top 25") {
$url = get_stylesheet_directory_uri() .'/custom_img/25.png';
}
if ($ranking == "Top 24") {
$url = get_stylesheet_directory_uri() .'/custom_img/24.png';
}
return $url;
}
add_filter( 'bp_core_default_avatar_user', 'bpfr_my_new_avatar_url' );
Create a profile field called “ranking” with 2 options (top 24 & top 25).
Create a folder in your child-theme called “custom_img” and add 2 pictures: 24.png & 25.png (250×250)
If everybody must those avatars, disallow avatar upload in BP settings.
Site default avatar stays as Mystery Man (wp default setting).
You have also to get rid of Gravatar, so you must add this to bp-custom.php
add_filter('bp_core_fetch_avatar_no_grav', '__return_true');
The thing who doesn’t work is related to X & Y are now friends. Both willhave the same avatar.
Can probably by better improved.
Tried a new code using bp_profile_field_data:
wpse_49216_my_new_avatar_url function () {
$ current_user = wp_get_current_user ();
$ current_user_id = $ current_user-> ID;
global $ bp;
$ var = bp_profile_field_data (array ('user_id' => $ current_user_id, 'field' => 'ranking'));
if ($ var == "Cranking") {
return 'http://hsseek2.esy.es/wp-content/uploads/2015/04/lendario.png';
}
if ($ var == "Dranking") {
return 'http://hsseek2.esy.es/wp-content/uploads/2015/04/25.png';
}
}
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');
It now appears the name of the field on the homepage, but I need to treat the value returned by bp_profile_field_data it looks like is:
http://hsseek2.esy.es/
username: teste
password: 1234
What value the bp_profile_field_data returns? How can I treat it?
the code I am using is:
wpse_49216_my_new_avatar_url function () {
global $ bp;
$ranking = xprofile_get_field_data ('ranking', bp_get_member_user_id ());
if ($ranking == "Top 25") {
return 'http://hsseek2.esy.es/wp-content/uploads/2015/04/25.png';
}
if ($ gender == "Top 24") {
return 'http://hsseek2.esy.es/wp-content/uploads/2015/04/24.png';
}
}
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');
in function.php
The avatars only works when I’m in BuddyPress pages.
I want to make it work around the site by adding the following code passing the user ID I found searching for:
<? php
$ Userid = bp_loggedin_user_id ();
echo bp_core_fetch_avatar (array ('item_id' => $ id user));
?>
But in which .phpeu add file this code?
The avatars only works when I’m in BuddyPress pages.
I want to make it work around the site by adding the following code passing the user ID I found searching for:
<? php
$ Userid = bp_loggedin_user_id ();
echo bp_core_fetch_avatar (array ('item_id' => $ id user));
?>
But in which .phpeu add file this code?
Homepage:

Members area:

gave the following error:
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘: 1)’ at line 1]
SELECT id, user_id, field_id, value, last_updated FROM wp_bp_xprofile_data WHERE field_id = 2 AND user_id IN (displayed: 1)
Read on the internet that I must pass the id as parameter for bp_core_fetch_avatar:
<?php
$userid = bp_loggedin_user_id();
echo bp_core_fetch_avatar( array( ‘item_id’ => $userid) );
?>
But do not know where I have to put this code or how to implement in my code. Can you help me?
Try this:
function wpse_49216_my_new_avatar_url() {
global $bp;
if( bp_is_user() && !bp_get_member_user_id() ) {
$user_id = 'displayed: '. bp_displayed_user_id();
} else {
$user_id = 'get_member_user: '. bp_get_member_user_id();
}
$gender = xprofile_get_field_data ( 'ranking', $user_id );
if ($gender == "Top 25") {
return 'http://hsseek2.esy.es/wp-content/uploads/2015/04/25.png';
}
if ($gender == "Top 24") {
return 'http://hsseek2.esy.es/wp-content/uploads/2015/04/24.png';
}
}
add_filter ('bp_core_fetch_avatar_url', 'wpse_49216_my_new_avatar_url');
I used this code in function.php:
wpse_49216_my_new_avatar_url function () {
$gender = xprofile_get_field_data ('ranking', bp_get_member_user_id ());
if ($gender == "Top 25") {
return 'http://hsseek2.esy.es/wp-content/uploads/2015/04/25.png';
}
if ($gender == "Top 24") {
return 'http://hsseek2.esy.es/wp-content/uploads/2015/04/24.png';
}
}
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');
The avatar will not appear outside buddypress page, on any other page it appears. I read on the internet that I must pass the id of the User with bp_loggedin_user_id (). How do I implement this in my code?
bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full' ) );
‘full’ will be the large size at whatever that is set to – usually 150px.
<?php $user_id = get_current_user_id(); ?>
<a href="<?php echo bp_core_get_user_domain( $user_id ); ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $user_id ) ); ?></a>
Your request is more properly asked of the plugin creator.
You could try this:
Open birds-author-box\public\frontend.php and replace this:
if (get_the_author_meta('image', get_query_var('author')))
{
$content.= '<img class="birds_box_avatar" src="' . get_the_author_meta('image', get_query_var('author')) . '">';
}
else
{
$blank = plugin_dir_url(__FILE__) . 'img/blank.png';
$content.= '<img class="birds_box_avatar" src="' . $blank . '">';
}
with this:
$avatar_args = array(
'item_id' => get_the_author_meta('ID', get_query_var('author')),
'type' => 'thumb',
'html' => false
);
$content.= '<img class="birds_box_avatar" src="' . bp_core_fetch_avatar( $avatar_args ) . '">';
thank you @danbp I will start right away!
Here is were I am now (not working):
<?php
if ($entry[1] == xprofile_get_field_data(2, $user_id)); {
echo bp_core_fetch_avatar($user_id);
}
?>
I am using buddypress on my website, and when a user send’s a message its shows the real name of user and not the username, i want it to be username. I did go through the code for messages in bp-messages-template
function bp_message_get_recipient_tabs() {
$recipients = explode( ' ', bp_get_message_get_recipient_usernames() );
foreach ( $recipients as $recipient ) {
$user_id = bp_is_username_compatibility_mode() ? bp_core_get_userid( $recipient ) : bp_core_get_userid_from_nicename( $recipient );
if ( $user_id ) : ?>
<li id="un-<?php echo esc_attr( $recipient ); ?>" class="friend-tab">
<span><?php
echo bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15 ) );
echo bp_core_get_userlink( $user_id );
?></span>
</li>
<?php endif;
}
}
But this shows it is picking up username and not the real name. Can anyone tell me where to make a change so that it displays the username and not the real name of person.
Thanks!
Hi
I am using buddypress on my website, and when a user send’s a message its shows the real name of user and not the username, i want it to be username. I did go through the code for messages in bp-messages-template
function bp_message_get_recipient_tabs() {
$recipients = explode( ' ', bp_get_message_get_recipient_usernames() );
foreach ( $recipients as $recipient ) {
$user_id = bp_is_username_compatibility_mode() ? bp_core_get_userid( $recipient ) : bp_core_get_userid_from_nicename( $recipient );
if ( $user_id ) : ?>
<li id="un-<?php echo esc_attr( $recipient ); ?>" class="friend-tab">
<span><?php
echo bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15 ) );
echo bp_core_get_userlink( $user_id );
?></span>
</li>
<?php endif;
}
}
But this shows it is picking up username and not the real name. Can anyone tell me where to make a change so that it displays the username and not the real name of person.
Thanks!