BuddyDev

Search

Create separate member types that can't see each other

  • Participant
    Level: Enlightened
    Posts: 23
    Daria Wilczynska on #18331

    Hey Brajesh.

    I feel bad to ask but there is one more thing I want to add if it’s at all possible. My boyfriend suggested it and I like this idea.

    Is it possible to have an opt in or opt out checkbox for filtering member types. So let’s say, the standard is that all members from all member types can see each other, but, if you check the box in your profile settings (create a condition) then it hides you from other member types – in this case I would designate International member type – that could be specified in php or in additional setting you add. It could work in reverse too. Similar concept like Privacy setting in BP which hides you from other members or only shows you to friends if you choose to hide yourself.

    The reason I’m asking about it is I spoke to some people and also I did a HotJar poll on my site last couple of days and 75% of poll takers have expressed interest in meeting members from other countries and long distance relationship so I am on the fence what to do – hide or not. But, what goes along with it, there will be people who do not want to be contacted by people from other countries and that might make them upset to get a lot of messages from people they have no interest in due to distance. So if they can opt out, that can make everyone be happy.

    Is that a crazy/complicated thing to ask or is that a simple enough function? 🙂

    Daria

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #18363

    Hi Daria,
    Thank you for sharing more details and the patience.

    1. I am sorry but the above is not doable with BuddyPress Member Types alone( May be we can use a 3rd member type called international? I will be thinking a bit more about it today).

    2. The opposite of it(which member types a user want to see is easily doable).

    The member type is like category so we can include whole category or exclude whole category but can not do the same for individuals.

    It is possible to implement it as non member type solution though.

    PS:- I will share the code for member type by Sunday evening.

    Thank you
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 23
    Daria Wilczynska on #18376

    Thanks Brajesh. I look forward to seeing the updated plugin. Maybe we can discuss the opt out outside of this plugin and see if you can do it as a custom php thing for me. I was hoping it was an easy thing but I understand it might not be.

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #18378

    Hi Daria,
    Thank you. Yes, we can do that in future.

    Here I am going to show two approaches( I will prefer second if feasible).

    Strategy 1 :- Using member_type__in like this

    
    
    /**
     * Restrict members list by member type.
     *
     * @param array $args args.
     *
     * @return array
     */
    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'   => array( 'international', 'female' ),
    		'female' => array( 'canada',  'male' ),
    	);
    
    	$member_types = bp_get_member_type( get_current_user_id(), false );
    	$member_type = '';
    	// check if the user has a member type that may trigger the selection.
    	foreach ( $member_types as $member_type_name ) {
    		if ( isset( $visible_types_map[ $member_type_name ] ) ) {
    			$member_type = $member_type_name; //found.
    			break;
    		}
    	}
    
    	// 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__in'] = $visible_types_map[ $member_type ];
    	return $args;
    
    }
    
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_filter_by_opposite_member_type' );
    
    

    The problem with this approach is that instead of “AND”ing the coditions are “OR”ed. Eg. Instead of ‘international’ AND ‘female’ it becomes ‘international’ OR ‘female’ and it does not server our purpose.

    Strategy 2: Use member_type__not_in to exclude member types. It only works if all the members have atleast one member type assigned(It does not matter which member type)

    
    /**
     * Restrict members list by member type.
     *
     * @param array $args args.
     *
     * @return array
     */
    function buddydev_filter_by_opposite_member_type2( $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'   => array( 'international', 'female' ),
    		'female' => array( 'canada',  'male' ),
    	);
    
    	$member_types = bp_get_member_type( get_current_user_id(), false );
    	$member_type = '';
    	// check if the user has a member type that may trigger the selection.
    	foreach ( $member_types as $member_type_name ) {
    		if ( isset( $visible_types_map[ $member_type_name ] ) ) {
    			$member_type = $member_type_name; //found.
    			break;
    		}
    	}
    
    	// 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;
    	}
    	// Find all registered types and deduce the types which are invisible.
    	$all_types = bp_get_member_types(array(), 'names' );
    	$invisible_types = array_diff( $all_types, (array) $visible_types_map[ $member_type ] );
    
    	$args['member_type__not_in'] = $invisible_types;
    	return $args;
    
    }
    
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_filter_by_opposite_member_type2' );
    

    You only specify which member types will be visible. We calculate the invisible types automatically. This works to AND our conditions but there is an issue. If a user does not have any member type, they will show up in the list. In other words, if all uses are guaranteed to have at least 1 member type, it works.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 23
    Daria Wilczynska on #18391

    Thanks Brajesh. I’ll check this code out tonight and see what it does.

    I still want to pursue the opt out button so please let me know how to discuss with you custom work. While a lot of people have expressed their
    interest in meeting people from abroad, enough people also don’t so at the least I would love to get more info from you on what you can do and how complex is it.

    I keep getting more international members sign up using US & Canada membership and I don’t want to kick them out at this point, so I hope to figure this out sooner than later. Thanks.

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #18397

    Hi Daria,
    Sure, please do let me know how it goes.

    About the global members options, It will be nice if we can discuss after 1st Nov. I have some urgent tasks that need attention till then and I will be glad to take over it after that.

    I am sharing my email in next private reply.

    Thank you
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #18398
    This reply has been marked as private.

You must be logged in to reply to this topic.

This topic is: not resolved