BuddyDev

Search

[Resolved] Using Member Type Generator with BP core widgets

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #24615

    Hi Brajesh, I’m using Who’s Online, Members and Most Visited Users BP core widgets, which are displaying all members. I find it strange that there are no options for displaying certain member types only.

    I am using Member Type Generator, and would like these widgets to return members of that member type, and an option for showing another member type than your own, like if you are logged in as student, only teachers are displayed, and the opposite.

    How do I achieve this?, perhaps Member Types Pro is the solution?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
  • Participant
    Level: Yogi
    Posts: 1105
    calu on #24638

    Hi Brajesh, thanks for sharing this topic, and the code, which concerns the members list, but will it also affect the BP core widgets?

    Regards
    Carsten

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #24639

    Hi again, I tested the first code based on gender, but it didn’t make any changes in my Members list, which are still showing both genders.

    Best
    Carsten

    function buddydev_filter_by_opposite_member_type( $args ) {
    
    	//  No need to change members listing if the user is not logged in.
    	if ( ! is_user_logged_in() ) {
    		return $args;
    	}
    
    	// Map of visible member types based on the member type.
    	// 'male', 'female' are member type names.
    	$visible_types_map = array(
    		'male'   => 'female',
    		'female' => 'male',
    	);
    
    	$member_type = bp_get_member_type( get_current_user_id(), true );
    
    	// If the user does not have a member type
    	// or if the user does not need the restriction.
    	if ( empty( $member_type ) || empty( $visible_types_map[ $member_type ] ) ) {
    		return $args;
    	}
    
    	$args['member_type'] = $visible_types_map[ $member_type ];
    
    	return $args;
    
    }
    
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_filter_by_opposite_member_type' );
  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #24640

    Hi Carsten,
    1. Since BuddyPress member lists don’t have context, It will work for all list.

    2. You will need to map the member type correctly in $visible_types_map

    Please check your registered member type names(unique names) and use that.

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #24641

    Hi Brajesh, yes of course, forgot about the mapping, it’s working now, except for the Most Visited widget?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #24645

    Hi Carsten,
    Thank you for confirming.

    What is Most visited widget? Is it the one from recent visitors plugin?

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #24647

    Hi Brajesh, yes, you are right, it’s from the Recent Profile Visitors plugin

    Regards
    Carsten

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #24649

    It would be really nice, if this plugin also would be affected by the member type code

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #24653

    Hi Carsten,
    The plugin does not support member type currently. I will look into it today and update you if we are able to provide an update soon or not.

    Thank you
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved