Hello, sorry, I asked already my question in the comments of the page about custom avatars by type, but I think perhaps it’s better to ask it on the forum.
BP Member type (free) installed.
3 members types created (classique, premium, jeune-pro).
I wish to display different default avatar by type when I display the list of members from a group.I try to add code into bp-custom.php but it didn’t work.
So, I added at the bottom of functions.php :
//Customiser avatars buddypress add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' ); function buddydev_set_default_use_avatar_based_on_member_type( $avatar, $params) { $user_id = $params['item_id']; $type = bp_get_member_type( $user_id ); if ( $type == 'premium' ) { $avatar = 'http://example.com/avatar-premium.png';// get_template_directory_uri() . '/assets/images/avatar-premium.png'; } elseif( $type =='classique' ) { $avatar = 'http://example.com/female.png';//get_template_directory_uri() . '/assets/images/avatar-premium.png'; } elseif( $type =='jeunepro' ) { $avatar = 'http://example.com/avatar-jeunepro.png';//get_template_directory_uri() . '/assets/images/avatar-jeunepro.png'; } else { $avatar = 'http://example.com/unknown.png';//get_template_directory_uri() . '/assets/images/unknown.png';; } return $avatar; }
I tried also with adding this (found in an other post)
add_filter( 'bp_core_default_avatar_user', 'buddydev_set_default_use_avatar_based_on_member_type', 10, 2 );
But nothing changes. The src is always :
src=”http://mysite.com/wp-content/plugins/buddypress/bp-core/images/mystery-man-50.jpg”What is wrong ?
Thanks a lot for your help !!
regards
- This topic was modified 6 years, 2 months ago by Brajesh Singh. Reason: Update code to use backticks
Hi CDS,
You have done it correctly by addingadd_filter( 'bp_core_default_avatar_user', 'buddydev_set_default_use_avatar_based_on_member_type', 10, 2 );
That line is required.
I am hoping that example.com is replaced with the correct url path.
Also, I will suggest that you should try changing a user’s member type and see if it has any effect on the avatar. Your code seems fine to me.
Regards
BrajeshHi Brajesh,
Thanks for your reply !
Thus the add_filter is at the good place in the code ?
Yes, I replaced the url.
The exact code I added in functions.php is :‘// Desactiver avatar buddy
add_filter( ‘bp_core_fetch_avatar_no_grav’, ‘__return_true’ );
//Customiser avatars buddypressfunction buddydev_set_default_use_avatar_based_on_member_type( $avatar, $params) {
$user_id = $params[‘item_id’];$type = bp_get_member_type( $user_id );
if ( $type == ‘premium’ ) {
$avatar = get_template_directory_uri() . ‘/assets/images/avatar-premium.png’;
} elseif( $type ==’classique’ ) {
$avatar = get_template_directory_uri() . ‘/assets/images/avatar-classique.png’;
} elseif( $type ==’jeune-pro’ ) {
$avatar = get_template_directory_uri() . ‘/assets/images/avatar-jeunepro.png’;
} else {
$avatar = ‘http://example.com/unknown.png’;//get_template_directory_uri() . ‘/assets/images/unknown.png’;;
}return $avatar;
}
add_filter( โbp_core_default_avatar_userโ, โbuddydev_set_default_use_avatar_based_on_member_typeโ, 10, 2 );’But the default avatar isn’t desactivated ๐ it’s always the stupid myster man ๐
What is it missing ? Perhaps an endif ? I don’t know, I’m not a very good php dev ๐
I tried also by changing the default avatar in Settings -> Discussion.
I tried by changing a member of type.
No change …If you have an idea …
thanks a lot !!!
Hi CDS,
Thank you for the details. Let me try this code on a site of mine and get back to you later today.
Thank you
BrajeshHi CDS,
I have tested it and the code from the first post is working properly for me.Please make sure you are using the member type name from this box
https://i.imgur.com/rDT9yW0.pngRegards
BrajeshHello Brajesh, I’m sorry I come again with my problem ๐ I get the really path to the image, I use correctly the name of the member type as on your screen, but it’s always the path to the buddypress default image. I created the member types with the free version of BuddyPress Member Types Generator. I tried to get the code in bp-custom.php but a blank page happened. I’m not sure I did that correctly. Is it necessary to put this file directly in the plugin directory or in the buddypress directory ?
Is it neccessary to add anything before the code ?
Please, what can I try ?Thanks a lot for your patience
Best regards
Hi CDS,
I am sorry about this.Are you using a custom theme? Is your theme overriding the default avatar in any way?
Regards
BrajeshHi Brajesh, you’re very kind ! You gave me a way to search !
The theme is Kleo wich has settings for Buddypress but nothing about avatar, only about the ‘Profile & Group Icons style’.
There is a buddypress directory in the plugins repertory. But there is also an buddypress directory in themes > Kleo. So I looked into members.php in this directory. The code seems to be similar that I can see with the Insepctor :
‘ <li class=”kleo-masonry-item”>
<div class=”member-inner-list animated animate-when-almost-visible bottom-to-top”>
<div class=”item-avatar rounded”>
“>
<?php bp_group_member_avatar_thumb(); ?>
<?php do_action(‘bp_member_online_status’, bp_get_member_user_id()); ?>
</div>’I tried to put the bp-custom.php in the kleio directory but nothing change.
What do you think about that ? I suppose that the bp_group_member_avatar_thumb is defined in functions.php ?
I’ll look at this but if you have an idea …
I think the goal is not more so fare ๐ (sorry, I’m french I don’t know if it’s correct !)Best regards !
The topic ‘ [Resolved] Custom avatar by type’ is closed to new replies.