-
Author
-
August 5, 2018 at 20:59 #205491tulipworkParticipant
Hi!
How to prevent male users to see other male users but only female? And same for women?
Thank you very much.
August 5, 2018 at 21:14 #205493Kieran_SQModeratorHi,
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 solutionIf 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.
August 5, 2018 at 21:43 #205498tulipworkParticipantIt 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!
August 5, 2018 at 21:49 #205499Kieran_SQModeratorHi,
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 solutionIf 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.
August 5, 2018 at 22:29 #205500tulipworkParticipantHi!
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.August 5, 2018 at 22:37 #205501Kieran_SQModeratorHi,
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 solutionIf 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.
August 5, 2018 at 23:07 #205502tulipworkParticipantThanks for your help!
Here is the code:
COPY CODEadd_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; }
August 5, 2018 at 23:23 #205503Kieran_SQModeratorHi,
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 CODEadd_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 solutionIf 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.
August 5, 2018 at 23:48 #205505Kieran_SQModeratorGlad 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 solutionIf 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.
August 17, 2018 at 17:29 #206703tulipworkParticipantHi,
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.
August 17, 2018 at 17:44 #206704Kieran_SQModeratorHi,
You could try this instead which will check if the user doesn’t have the activate plugins capability (administrator).
COPY CODEadd_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 solutionIf 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.
August 17, 2018 at 18:04 #206711Kieran_SQModeratorHi,
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 solutionIf 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.
August 17, 2018 at 19:08 #206724tulipworkParticipantI,
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…
August 17, 2018 at 19:37 #206731Kieran_SQModeratorHi,
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 solutionIf 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.
August 17, 2018 at 19:40 #206732tulipworkParticipant– Revert the code to the version before the admin check: Page 2 is working
– Remove the code entirely: page 2 is workingAugust 17, 2018 at 19:49 #206733Kieran_SQModeratorHi,
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 solutionIf 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.
August 17, 2018 at 20:01 #206736Kieran_SQModeratorHi,
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 solutionIf 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.
August 17, 2018 at 23:30 #206787tulipworkParticipantHi 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!
August 18, 2018 at 16:05 #206835Kieran_SQModeratorHi,
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 solutionIf 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.
-
AuthorPosts
You must be logged in to reply to this topic.