This topic has 22 replies, 2 voices, and was last updated 6 years by tulipwork.

  • Author
  • #205491
     tulipwork
    Participant

    Hi!

    How to prevent male users to see other male users but only female? And same for women?

    Thank you very much.

    #205493
     Kieran_SQ
    Moderator

    Hi,

    Please see here for how to restrict the members directory in that way

    https://wordpress.org/support/topic/prevent-same-sex-search-on-dating-site/#post-10095615

    This code would need to be added to bp-custom.php so it is called early enough to work properly. This file does not exist by default and you will need to create your bp-custom.php file and upload it directly into /wp-content/plugins/ folder.

    For more information on the bp-custom.php file please see this buddypress codex article https://codex.buddypress.org/themes/bp-custom-php/

    Thanks,

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #205498
     tulipwork
    Participant

    It works like a charm! Sorry, I should have look on Google by myself:)

    Thank you so much for this great support! Going to rate 5/5 on themeforest!

    #205499
     Kieran_SQ
    Moderator

    Hi,

    Glad to hear this worked for you 🙂 And I look forward to your review.

    All the best,

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #205500
     tulipwork
    Participant

    Hi!
    Just a question: on my homepage, only male users are displaying now. Do you know how to fix it?
    On the “recent active members” widget, all gender are displaying.

    #205501
     Kieran_SQ
    Moderator

    Hi,

    When I am logged in as a male user I see only female users in the carousel widget. If I switch to a female user I see only male users in the same carousel.

    I assume you mean whilst logged out? If so it may be possible to use is_user_logged_in() in the if statement so this code is only run for logged in users. Please can you share the exact code you used here with a single code tag before and after the code so no formatting is lost.

    Thanks,

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #205502
     tulipwork
    Participant

    Thanks for your help!

    Here is the code:

    COPY CODE
    add_filter ('bp_ajax_querystring', 'modify_members_loop', 20, 2);
    function modify_members_loop ($qs=false, $object=false)
    {
    global $wpdb;
    if ($object != 'members') return $qs;
    
    // figure out if the logged-in user is male or female
    $gender = xprofile_get_field_data (2, bp_loggedin_user_id ());
    
    if ($gender == 'Male')
    $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value = 'Female'";
    else
    $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value = 'Male'";
    
    $custom_ids = $wpdb->get_col ($query);
    
    $args = wp_parse_args ($qs);
    $args['include'] = implode (',', $custom_ids);
    $qs = build_query ($args);
    
    return $qs;
    }
    #205503
     Kieran_SQ
    Moderator

    Hi,

    I tested this locally. It restricts logged in users to opposite sex and shows all to any logged out user. Let me know if this works for you or not.

    COPY CODE
    add_filter ('bp_ajax_querystring', 'modify_members_loop', 20, 2);
    function modify_members_loop ($qs=false, $object=false) {
    
        if (is_user_logged_in() ){
    
            global $wpdb;
            if ($object != 'members') return $qs;
    
            // figure out if the logged-in user is male or female
            $gender = xprofile_get_field_data (2, bp_loggedin_user_id ());
    
            if ($gender == 'Male')
            $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value = 'Female'";
            else
            $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value = 'Male'";
    
            $custom_ids = $wpdb->get_col ($query);
    
            $args = wp_parse_args ($qs);
            $args['include'] = implode (',', $custom_ids);
            $qs = build_query ($args);
    
            return $qs;
        }
    }

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Ticket solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #205504
     tulipwork
    Participant

    It works perfectly! THOUSAND THANKS.

    #205505
     Kieran_SQ
    Moderator

    Glad to hear and you’re very welcome 🙂

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #206703
     tulipwork
    Participant

    Hi,

    Do you know how to prevent this code from running for the admin user? Just to apply it to members and let admin see all genders?

    Thank you so much.

    #206704
     Kieran_SQ
    Moderator

    Hi,

    You could try this instead which will check if the user doesn’t have the activate plugins capability (administrator).

    COPY CODE
    add_filter ('bp_ajax_querystring', 'modify_members_loop', 20, 2);
    function modify_members_loop ($qs=false, $object=false) {
    
        if (is_user_logged_in() && !current_user_can('activate_plugins') ){
    
            global $wpdb;
            if ($object != 'members') return $qs;
    
            // figure out if the logged-in user is male or female
            $gender = xprofile_get_field_data (2, bp_loggedin_user_id ());
    
            if ($gender == 'Male')
            $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value = 'Female'";
            else
            $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value = 'Male'";
    
            $custom_ids = $wpdb->get_col ($query);
    
            $args = wp_parse_args ($qs);
            $args['include'] = implode (',', $custom_ids);
            $qs = build_query ($args);
    
            return $qs;
        }
    }

    Thanks,

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Ticket solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #206710
     tulipwork
    Participant

    Perfect, thank you so much!

    #206711
     Kieran_SQ
    Moderator

    Hi,

    No worries, happy to help 🙂

    All the best,

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #206724
     tulipwork
    Participant

    I,

    I just notice that when a user scroll down and goes to page 2, it’s working fine. However, it’s not working for the admin: the page 2 loads the same users than the page 1…

    #206731
     Kieran_SQ
    Moderator

    Hi,

    It seems unlikely that adding the admin check would cause this issue. Can you therefore do the following two tests and let me know the outcome for each. Please completely purge your website cache and browser cache for each step to ensure you have the latest files.

    – Revert the code to the version before the admin check. Does page 2 work or not work as expected?
    – Remove the code entirely. Does page 2 work or not as expected?

    Thanks,

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #206732
     tulipwork
    Participant

    – Revert the code to the version before the admin check: Page 2 is working
    – Remove the code entirely: page 2 is working

    #206733
     Kieran_SQ
    Moderator

    Hi,

    That’s really strange. You’re using the code in bp-custom.php and not functions.php?

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #206734
     tulipwork
    Participant

    Absolutely.

    #206736
     Kieran_SQ
    Moderator

    Hi,

    I think this may be related to ajax but I am not able to test as I am currently not in the office. I’ll have to look into this in more detail tomorrow.

    If it is related to ajax I wouldn’t be able to extend the above code, but I could probably make a change to SweetDate (on your site only) that disabled the ajax element of the members directory but this would mean the url would no longer be /members/ for page 2 but /members/page-2 (or similar), is that okay?

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #206787
     tulipwork
    Participant

    Hi Kieran,

    If it’s due to Ajax, we will keep the current code, and I’ll create a female admin to see male members. Don’t worry about that, it’s not a big problem!

    If it’s not due to ajax and if there is a way to improve the current function, let’s try! If not, no problem!

    Thanks a lot!

    #206835
     Kieran_SQ
    Moderator

    Hi,

    Without disabling ajax on the members directory I am unable to resolve the page 2 issue with the admin check, sorry.

    All the best,

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #206842
     tulipwork
    Participant

    No problem, you already help me a lot!

Viewing 23 posts - 1 through 23 (of 23 total)

You must be logged in to reply to this topic.

Log in with your credentials

Forgot your details?