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!:)Thank you.
I sincerely appreciate your kindness and patience with us.Regards
BrajeshHi Fillip,
I am sorry for the delay.Please take a look at these lines near line 112 in bp-friends-suggestions-pro-functions.php
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 ); } }
I would suggest replacing them with if( is_array( $values ) ) { $value = maybe_serialize( $value );}
and then using Like operator for match. That should make it work.Regards
BrajeshHi 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
AlexHi Alex,
Please make sure you are using maybe_serialize and not maybe_unserialize. The former will always return a serialized string.Regards
BrajeshHi,
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}
thrownI am sorry, I typed values instead of value in the suggested condition.
Here is the correct code.
if( is_array($value)) { $value = maybe_serialize( $value ); }
Please try it.
Regards
BrajeshSadly, 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 :/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
AlexHI Alex,
I am sorry for the delayed reply.I have been thinking a solution about it. There is a solution without BuddyPress Friends suggestions pro though. xprofile query are costly(slow), so I am not sure if we should do that or not.
The approach is to first create a xprofile query builder or this field
function bpfscustom_get_multiselect_field_query( $user_id, $field_id, $match_field_id, $compare ) { $field_data = xprofile_get_field_data( $field_id, $user_id ); if ( empty( $field_data ) ) { return array(); } if ( ! is_array( $field_data ) ) { return array( array( 'field' => $match_field_id, 'value' => $field_data, 'compare' => $compare, ) ); } $query = array(); foreach ( $field_data as $datum ) { $query[] = array( 'field' => $match_field_id, 'value' => $datum, 'compare' => $compare, ); } return $query; }
and then use it in the bp-friend-suggestions-pro-functions.php near line 119
if ( $rule['field_id'] == ACTUAl_MULTI_SELECT_FIELD_ID ) { $queries = bpfscustom_get_multiselect_field_query( $user_id, $rule['field_id'], $rule['match_field_id'], $compare ); if ( ! empty( $queries ) ) { $xp_query = array_merge( $xp_query, $queries ); } continue; }
You should replace the
ACTUAl_MULTI_SELECT_FIELD_ID
with the numeric field id for the multi select.So, the lines in this file which looked like this’
$xp_query[] = array( 'field' => $rule['match_field_id'], 'value' => $value, 'compare' => $compare, );
will be
if ( $rule['field_id'] == ACTUAl_MULTI_SELECT_FIELD_ID ) { $queries = bpfscustom_get_multiselect_field_query( $user_id, $rule['field_id'], $rule['match_field_id'], $compare ); if ( ! empty( $queries ) ) { $xp_query = array_merge( $xp_query, $queries ); } continue; } $xp_query[] = array( 'field' => $rule['match_field_id'], 'value' => $value, 'compare' => $compare, );
Hope that helps.
Regards
Brajesh
You must be logged in to reply to this topic.