Replies
- Filip Alexander on January 24, 2025 at 2:33 pm in reply to: BuddyDev Friends Suggestions Pro “like/not like” #54997
Hi Brajesh,
thank you so much, this works just perfectly!! You’re amazing! I will keep in mind it could get resource heavy and change the setup in case my user base would grow a lot, but for now I don’t rly have that many users so it should be okay for some time. I really really appreciate you taking your time to create a solution for me.
I’m now trying to work on the nested conditions (as i mentioned before in my first post) and i came up with something like this:function bp_friends_suggestions_pro_get_xprofile_query($suggestion_rule_id) { if (!is_user_logged_in() || !$suggestion_rule_id || empty(get_post_meta($suggestion_rule_id, '_is_active', true))) { return array(); } if (!bp_is_active('xprofile')) { return array(); } $user_id = bp_loggedin_user_id(); $matching_rules = (array) get_post_meta($suggestion_rule_id, '_matching_rules', true); // New meta field for rule grouping $rule_groups = (array) get_post_meta($suggestion_rule_id, '_rule_groups', true); if (empty($matching_rules)) { return array(); } $xp_query = array(); $mandatory_rules = array(); $optional_rules = array(); // Split rules into mandatory and optional based on group settings foreach ($matching_rules as $index => $rule) { if (empty($rule['field_id']) || empty($rule['match_field_id']) || empty($rule['operator'])) { continue; } $value = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($rule['field_id'], $user_id)); // Determine comparison operator switch ($rule['operator']) { case '=': case '!=': case 'LIKE': case 'NOT LIKE': $compare = $rule['operator']; break; case '<': $compare = '>'; // opposite break; case '<=': $compare = '>='; break; case '>': $compare = '<'; break; case '>=': $compare = '<='; break; default: $compare = null; break; } if (!$compare) { continue; } // Handle array values if (is_array($value) && !in_array($compare, array('IN', 'NOT IN'))) { if (count($value) === 1 && !bp_friends_suggestions_pro_is_multi_valued_field($rule['match_field_id'])) { $value = array_pop($value); } else { $value = maybe_serialize($value); } } $query_item = array( 'field' => $rule['match_field_id'], 'value' => $value, 'compare' => $compare ); // Special handling for field_id 43 if ($rule['field_id'] == '43') { $queries = bpfscustom_get_multiselect_field_query( $user_id, $rule['field_id'], $rule['match_field_id'], $compare ); if (!empty($queries)) { if (isset($rule_groups[$index]) && $rule_groups[$index] === 'mandatory') { $mandatory_rules = array_merge($mandatory_rules, $queries); } else { $optional_rules = array_merge($optional_rules, $queries); } } continue; } // Add to appropriate group based on rule_groups setting if (isset($rule_groups[$index]) && $rule_groups[$index] === 'mandatory') { $mandatory_rules[] = $query_item; } else { $optional_rules[] = $query_item; } } // Build nested query structure if (!empty($mandatory_rules)) { $xp_query[] = array( 'relation' => 'AND', 'rules' => $mandatory_rules ); } if (!empty($optional_rules)) { $xp_query[] = array( 'relation' => 'OR', 'rules' => $optional_rules ); } if (!empty($xp_query)) { $xp_query['relation'] = 'AND'; } return $xp_query; }
and then this:
// Example of how to store rule groups $rule_groups = array( 0 => 'mandatory', // First rule is mandatory 1 => 'mandatory', // Second rule is mandatory 2 => 'optional', // Third rule is optional 3 => 'optional', // Fourth rule is optional 4 => 'optional' // Fifth rule is optional ); update_post_meta($suggestion_rule_id, '_rule_groups', $rule_groups);
Could you please just tell me what you think of this approach? I originally wanted to incorporate the ability to choose whether the condition is mandatory or optional into the form, but I just couldn’t rly manage. I would love any form of feedback from you, but it’s totally okay if you don’t have a time/space for it, as im already extremely grateful for your help regarding the multi select.
Best regards
Alex - Filip Alexander on January 20, 2025 at 9:33 pm in reply to: BuddyDev Friends Suggestions Pro “like/not like” #54769
Hi Brajesh,
I just wanted to thank you again very much for your time and effort in helping me. In the end I sort of found a kinda loophole (i guess). I will first use LIKE to show the logged-in users if they’re match (as in if the logged-in single value value fits one of multiselect values from the match). Then i will use do_action before and after the members loop that’s generated through the plugin to filter out any matched users that don’t fit the logged-in users preferences.
I will probably write a function that I’ll hook to the do_action before the members loop to take each member’s data, check it and if it doesnt match the logged-in user filter that user out.
I wrote a little bit of a similar function for myCred (bc MyCred has an add-on where a user can lock their profile behind paywall, but it only locks activity content and not the media attached to the activity, so i wrote function that dynamically removes any media from users whose profile is marked as paywalled). I hope the approach will work and be somehow similar to me current function.
So thank you again for your time and i hope I didn’t take much of it.Regards
Alex - Filip Alexander on January 18, 2025 at 9:29 pm in reply to: BuddyDev Friends Suggestions Pro “like/not like” #54682
Sadly, still doesnt work :/
Just to make sure I described it correctly (my english is not really the best)I want the logged-in user to have multi select profile field (lets say checkbox for example). The logged in user can check multiple hobbies, let’s say: reading, studying and music. The matched user profile field is a single value field, dropdown, they check only one, lets say reading. Now since one of the logged-in user value in the multi select matches with the matched user single value, i would love if it would show a match.
Currently after the change it doesnt work at all :/
If I keep the originall code and the logged in user picks only one value in the multi select and that value corresponds with the value of the matched profile, it will actually show a match, but only if the logged-in user picks just one value from the multi select, which is not ideal for my solution :/ - Filip Alexander on January 18, 2025 at 8:55 pm in reply to: BuddyDev Friends Suggestions Pro “like/not like” #54680
Hi,
Im really trying, I replaced this:
if ( is_array( $value ) && ! in_array( $compare, array( ‘IN’, ‘NOT IN’ ) ) ) {
if ( count( $value ) === 1 && ! bp_friends_suggestions_pro_is_multi_valued_field( $rule[‘match_field_id’] ) ) {
$value = array_pop( $value );
} else {
$value = maybe_serialize( $value );
}
}with this:
if( is_array( $values ) ) { $value = maybe_serialize( $value );}so the final code looks like this:
// must have a valid comparator.
if ( ! $compare ) {
continue;
}// For the data fields which store their values as serialized string, we need to repurpose the value.
if( is_array( $values ) ) { $value = maybe_serialize( $value );}$xp_query[] = array(
‘field’ => $rule[‘match_field_id’],
‘value’ => $value,
‘compare’ => $compare,
);
}But when I try to save the changes, wordpress won’t let me do it due to the error i pasted here, the whole error is like this:
Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, array given in wp-content/plugins/buddyboss-platform/bp-xprofile/classes/class-bp-xprofile-query.php:452
Stack trace:
#0 wp-content/plugins/buddyboss-platform/bp-xprofile/classes/class-bp-xprofile-query.php(452): trim()
#1 wp-content/plugins/buddyboss-platform/bp-xprofile/classes/class-bp-xprofile-query.php(261): BP_XProfile_Query->get_sql_for_clause()
#2 wp-content/plugins/buddyboss-platform/bp-xprofile/classes/class-bp-xprofile-query.php(213): BP_XProfile_Query->get_sql_for_query()
#3 wp-content/plugins/buddyboss-platform/bp-xprofile/classes/class-bp-xprofile-query.php(323): BP_XProfile_Query->get_sql_clauses()
#4 wp-content/plugins/buddyboss-platform/bp-xprofile/bp-xprofile-filters.php(625): BP_XProfile_Query->get_sql()
#5 wp-includes/class-wp-hook.php(324): bp_xprofile_add_xprofile_query_to_user_query()
#6 wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#7 wp-includes/plugin.php(565): WP_Hook->do_action()
#8 wp-content/plugins/buddyboss-platform/bp-core/classes/class-bp-user-query.php(553): do_action_ref_array()
#9 wp-content/plugins/buddyboss-platform/bp-core/classes/class-bp-user-query.php(203): BP_User_Query->prepare_user_ids_query()
#10 wp-content/plugins/bp-friends-suggestions-pro/src/core/bp-friends-suggestions-pro-functions.php(185): BP_User_Query->__construct()
#11 wp-content/plugins/bp-friends-suggestions-pro/src/core/class-bp-friends-suggestions-pro-widget.php(66): bp_friends_suggestions_pro_get_suggested_user_ids()
#12 wp-includes/class-wp-widget.php(394): BP_Friends_Suggestions_Pro\Core\BP_Friends_Suggestions_Pro_Widget->widget()
#13 wp-includes/widgets.php(845): WP_Widget->display_callback()
#14 wp-content/themes/buddyboss-theme-child/sidebar-buddypress.php(30): dynamic_sidebar()
#15 wp-includes/template.php(810): require_once(‘…’)
#16 wp-includes/template.php(745): load_template()
#17 wp-includes/general-template.php(136): locate_template()
#18 wp-content/themes/buddyboss-theme-child/buddypress.php(107): get_sidebar()
#19 wp-includes/template-loader.php(106): include(‘…’)
#20 wp-blog-header.php(19): require_once(‘…’)
#21 index.php(17): require(‘…’)
#22 {main}
thrown - Filip Alexander on January 18, 2025 at 8:42 pm in reply to: BuddyDev Friends Suggestions Pro “like/not like” #54677
Hi Brajesh,
thank you so much for your effort, but when i try to replace these lines with the simplified version, it throws error sadly :/
Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, array given in wp-content/plugins/buddyboss-platform/bp-xprofile/classes/class-bp-xprofile-query.php:452
Any idea how to solve it please?
Thank you so much in advance.Regards
Alex - Filip Alexander on January 14, 2025 at 10:54 am in reply to: BuddyDev Friends Suggestions Pro “like/not like” #54656
1. Totally, I love playing inside the plugins, so I very appreciate your open mindset to it!
2. Thank you so much for that! I really don’t mind customizing the code myself, I do some work myself on almost every plugin I get, I just need a little nudge in the right direction and I hope i could do the rest, I know you must be insanely busy so Im really happy you even take your time to reply to me.
3. Please don’t be, it’s just a typo, nothing big haha, don’t worry about it!:) - Filip Alexander on January 14, 2025 at 10:40 am in reply to: BuddyDev Friends Suggestions Pro “like/not like” #54652
Hi,
1) thanks for your reply, i will definitely look into it!
2) I did try that but sadly it didn’t work :/ Could I have a different question regarding this? Currently, you can only do Logged-in user LIKE potential match, which means currenty it works such as “If logged-in single value field match anything in potential’s match longer text, it will match” – I tested this by switching the profile fields, as in the matching was done that potential match field was multi select while logged in user was single value (dropdown or just a word in text field) and it worked. Could you please point me to a possibility that I could internally “Switch” the logged-in and potential match in the query? So that i would check potential match single value LIKE logged-in multi select?
3) I already found the issue haha, it was a typo. In a template file for the buddyboss widget, you specified a path theme/buddypress/members/friends-suggestions-pro/default/widgets/, but it is actually theme/buddypress/members/***bp-***friends-suggestions-pro/default/widgets/, i realized when i looked into the original file path, so all good there.
Thank you again for your time and effort, i really appreciate it very much!
- Filip Alexander on January 13, 2025 at 10:36 am in reply to: BuddyDev Friends Suggestions Pro “like/not like” #54639
Hi,
Thanks for the reply.
1) thats a shame :/ do you think it would be possible to do at all?
2) well the thing is i need to compare two fields that are different kind, for example a multiselect checkbox and a dropdown, any way to do this please? Or in case it doesn’t work in current setup maybe you could point me in the direction of how it could be achieved by modifying the code?
I saw in and not in inside the code commented out, maybe i could use that?
3) i used exactly this path and it didn’t override the plug-in template :/
Thanks in advanfe for your reply.
- Filip Alexander on January 11, 2025 at 2:04 pm in reply to: BuddyDev Friends Suggestions Pro “like/not like” #54581
Hi,
sorry me again. One last question (so you can answer them all at once). In your template for the widget, you have a comment like this:
* You can override it in your theme/buddypress/members/friends-suggestions-pro/default/widgets/
But when i actually put the file in this path in my child theme it doesn’t work :/
- Filip Alexander on January 11, 2025 at 9:55 am in reply to: BuddyDev Friends Suggestions Pro “like/not like” #54562
Hi,
sorry for the double post, but I just found out something – when I use like, it doesnt work with arrays, meaning if I use LIKE and the logged in users profile field is a string, it won’t match users at all.
Like for example we have two field groups – About Me and Looking for. They share profile fields – in About me, you insert data about you and in Looking for you insert data your ideal match should have.
Lets say we have a field Body Type, the logged in user picks “Regular” from the dropdown and picks “Regular, Slim, Fit” from multiple choices in “Looking for”, i then set the rule that when logged in users “Looking for Body type” matches with “About me Body type” of a different user, its match, but it doesn’t work, because the logged in users data is array while the matched users is a string and currently there’s no way to set it up in the opposite way (matched user body type LIKE logged in user looking for body type).
Any help pls?