Hi there, I’m using the associated avatars, for each of my two gender member types.
The issue is that avatars in BP widgets like Online Members, Recent Visitors, and Recently Active Members are not changed to these avatars, and instead display an image place holder is displayed, which is a problem.
Would it be possible to have the Member Types Pro associated avatars displayed in the BP widgets?
Regards
CarstenHi Carsten,
Thank you for using the plugin.It seems form the screenshot that you have some kind of custom coding(or using some plugin). It may not be calling the bp_core_fetch_avatar().
Please share the details and Ravi or I will look into it and assist you.
Regards
BrajeshHi Brajesh, Thanks for helping out. I have not been able to address the issue yet, but I can see now that it is not related to MTP, as the issue persist, when using the code below I used before I started using MTP.
I have deactivated my child theme to rule out any issues there, and I have gone through my plugins, but I can’t see that any of these could affect this.
If you are willing to take a closer look on my site, please let me know, and I will send you the credentials.
Regards
Carsten//Using different default Avatar for BuddyPress //Disable Gravatar add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' ); //Using different default avatar based on BuddyPress profile field function buddydev_set_default_avatar_based_on_profile_field_data( $avatar, $params ) { $user_id = $params['item_id']; $field_id_or_name = 32;//Gender field Id, You may use field name e.g 'Gender'; //I suggest using id for performance reasons $gender = xprofile_get_field_data( $field_id_or_name, $user_id ); $gender = strtolower( $gender ); if ( $gender == 'man' ) { $avatar = 'https://wedate.dk/wp-content/uploads/2021/02/IMG_5356-e1620142850931.jpeg'; } elseif ( $gender == 'woman' ) { $avatar = 'https://wedate.dk/wp-content/uploads/2021/02/IMG_5357.jpeg'; } else { $avatar = 'https://wedate.dk/wp-content/uploads/woocommerce-placeholder.png'; } // note, you may play with the $param['type'] and use different image for full|thumb. return $avatar; } add_filter( 'bp_core_default_avatar_user', 'buddydev_set_default_avatar_based_on_profile_field_data', 10, 2 );
Hi Carsten,
Thank you.Yes, it seems something else is the issue.
I am unable to look into the site but I can get one of my team members to look into it. Please share the credentials and @ravisharma can look into it yesterday and assist you.
Regards
BrajeshHello Carsten,
I have checked and it seems you have not uploaded both versions of avatar i.e. full and thumb for member type. I have uploaded ones and it is working fine for me. Please check.
Take a look:
Regards
RaviHi Ravi, thanks for looking into this and for solving this issue for me.
I wasn’t aware of the required thumbnail avatar, so now it is working perfectly!
The only issues which remains, is that the BP widget avatars are not following members loop, or the gender based member filter below?
How do I make the code work on BP widgets as well?
Regards
Carsten/** * Filters Users based on Gender. Make sure only users of opposite genders are visible. */ class BuddyDev_Gender_Based_Member_Filter { /** * Boot * * @return BuddyDev_Gender_Based_Member_Filter */ public static function boot() { $self = new self(); $self->setup(); return $self; } /** * Setup hooks. */ private function setup() { add_filter( 'bp_after_has_members_parse_args', array( $this, 'filter_args' ) ); add_action( 'bp_template_redirect', array( $this, 'check_access' ), 10, 2 ); } /** * Modifies members loop args to filter out users of same gender. * * @param array $args Array of group allowed parameters. * * @return array */ public function filter_args( $args ) { // do not filter if user is not logged in, or is super admin or we are inside dashboard. if ( ! is_user_logged_in() || is_super_admin() || ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) { return $args; } $opposite_gender = $this->get_opposite_gender( bp_loggedin_user_id() ); if ( $opposite_gender ) { $args['member_type'] = $opposite_gender; } return $args; } /** * Restricts access to user profile. * * Only allows profile owner, user of opposite gender or site admins to view. */ public function check_access() { if ( ! is_user_logged_in() || ! bp_is_user() || bp_is_my_profile() || is_super_admin() ) { return; } $gender = $this->get_user_gender( bp_loggedin_user_id() ); if ( ! $gender ) { return; } // do not allow access for same gender. if ( bp_has_member_type( bp_displayed_user_id(), $gender ) ) { bp_core_add_message( __( 'Access denied.', 'yym-helper' ) ); bp_core_redirect( bp_loggedin_user_domain() ); } } /** * Returns user Gender. * * @param int $user_id user id. * * @return string|null */ private function get_user_gender( $user_id ) { $gender = null; $member_types = bp_get_member_type( $user_id, false ); if ( empty( $member_types ) ) { $gender = null; } elseif ( $this->is_user_male( $user_id ) ) { $gender = 'male'; } elseif ( $this->is_user_female( $user_id ) ) { $gender = 'female'; } return $gender; } /** * Finds the opposite gender for the given user. * * @param int $user_id user id. * * @return string|null */ private function get_opposite_gender( $user_id ) { $user_gender = $this->get_user_gender( $user_id ); if ( ! $user_gender ) { return null; } if ( 'male' === $user_gender ) { return 'female'; } elseif ( 'female' === $user_gender ) { return 'male'; } return null; } /*** * Checks if user is male or not. * * @param int $user_id User id to check. * * @return bool */ private function is_user_male( $user_id ) { return bp_has_member_type( $user_id, 'male' ); } /*** * Checks if user is female or not. * * @param int $user_id User id to check. * * @return bool */ private function is_user_female( $user_id ) { return bp_has_member_type( $user_id, 'female' ); } } BuddyDev_Gender_Based_Member_Filter::boot();
Hello Ravi, apparently there are two sets of BP Block Widgets, but only one of the sets are filtered by the Gender Based Member Filter:
What seems to be the core BP blocks are not:
What is the difference between the two sets of BP Block Widgets, obviously there is a difference?
Regards
Carsten
You must be logged in to reply to this topic.