excluding users from search

BP Profile Search › excluding users from search

  • Author
    Post
  • #9579 Reply
    Vasily
    Guest

    Dear Andrea,

    Can I exclude some users from searching? The idea is that those users who pay for participation will be in search, and those who do not pay will be excluded. Maybe I should use the plugin s2members?

    Sincerely
    Vasily

    #9580 Reply
    andrea
    Plugin Author

    Hi Vasily,

    How can you tell if the user is a paying member or not? Is that info stored in a profile field, in a role, or otherwise?

    #9581 Reply
    Vasily
    Guest

    Good question. I agree with you. While there is no such information. I just know who paid and who did not.

    #9582 Reply
    andrea
    Plugin Author

    If you store that information in a profile field with value, say, ‘paid’, you can build a directory of paying members with this shortcode:

    [bps_directory field_47='paid']

    (replace 47 with the actual ID of your profile field)

    Then you can select that directory as the results page of your search form, and you’ll get the search restricted to paying members.

    #9584 Reply
    Vasily
    Guest

    Nice, and thank you! But the users could change this profile field manually and appear in the search again I set the visibility only for me, but the user can change this value.

    #9585 Reply
    andrea
    Plugin Author

    You are right, that won’t work!

    You can use the member type instead. Build a directory of paying members with this shortcode:

    [bps_directory member_type='paid']

    (replace paid with the actual member type you give to paying members)

    Then you can select that directory as the results page of your search form, and you’ll get the search restricted to paying members.

    Please let me know if this works for you!

    #9586 Reply
    Vasily
    Guest

    For the site, I used BuddyPress Member Type Generator. There several types of users: Companies, Restaurants, Users, etc. Every user can be only one type of users.

    Does it mean that I need to create 2 of the additional types instead of the current one?

    For example: “Paid companies” and “Unpaid companies” instead of “Companies” and choose the right type for every company (depend on payment status)?

    Sincerely
    Vasily

    #9587 Reply
    andrea
    Plugin Author

    If you are already using member types for another purpose, I wouldn’t use them to also store the payment status.

    I’d go back to using a profile field, adding a plugin to prevent user modifications to that field. If you prefer, you could also use this quick and dirty code in bp-custom.php:

    add_action ('bp_members_admin_load', 'prevent_profile_field_update');
    add_action ('wp', 'prevent_profile_field_update');
    function prevent_profile_field_update ()
    {
    	if (!bp_current_user_can ('bp_moderate'))
    	{
    		$ID = 27;
    		if (isset ($_POST['field_ids']))
    		{
    			if (is_array ($_POST['field_ids']))  foreach ($_POST['field_ids'] as $k => $ids)
    				$_POST['field_ids'][$k] = implode (',', array_diff (explode (',', $_POST['field_ids'][$k]), array ($ID)));
    			else
    				$_POST['field_ids'] = implode (',', array_diff (explode (',', $_POST['field_ids']), array ($ID)));
    		}
    	}
    }

    Replace 27 with the ID of the field that users aren’t allowed to modify.

    #9588 Reply
    Vasily
    Guest

    A lot of thanks, Andrea!

    I found BuddyPress Non Editable Profile Fields plugin

    So, I need to return to your first advice.

    #9589 Reply
    andrea
    Plugin Author

    Yes, I think that’s a good solution.

    Please let me know if everything works for you!

    #9590 Reply
    Vasily
    Guest

    Yes, it works for me. A lot of thanks!!!

    #9591 Reply
    andrea
    Plugin Author

    You are welcome, all the best with your site!

    #9592 Reply
    Vasily
    Guest

    Very nice and thank you!
    Andrea, could you give me your e-mail? Maybe I can help you?

    #9594 Reply
    andrea
    Plugin Author

    Sure, I’ve just sent you an email. You can use that email address to contact me or, if you prefer, my Contact page.

Reply to: excluding users from search
My Information