<?php
// Custom profile search
function custom_profile_search()
{
global $wpdb, $bp;
$userids = array();
$search_fields_id = array(4, 5, 8, 65, 106, 117, 118, 119, 122, 244, 245, 264, 265);
$search_quote = trim($_POST['search_quote']);
$allowed_users_ids = array();
$options = get_option('contributors_list');
if ($options && count($options) > 0)
foreach ($options as $allowed_user_id => $value)
$allowed_users_ids[] = $allowed_user_id;
if ($_POST['custom_profile_search'] != true && $search_quote == "")
{
$userids = $allowed_users_ids;
}
else
{
if (bp_has_profile('hide_empty_fields=0')):
while (bp_profile_groups()): bp_the_profile_group();
while (bp_profile_fields()): bp_the_profile_field();
$id = bp_get_the_profile_field_id();
if (!in_array($id, $search_fields_id))
continue;
$sql = "SELECT user_id
FROM {$bp->profile->table_name_data}
WHERE field_id = $id";
$sql .= " AND value LIKE '%%$search_quote%%'";
$found = $wpdb->get_results($wpdb->prepare($sql));
if (count($found) > 0)
{
foreach ($found as $user)
{
$userid = $user->user_id;
if (!in_array($userid, $allowed_users_ids))
continue;
if (!in_array($userid, $userids))
$userids[] = $userid;
}
}
endwhile;
endwhile;
endif;
}
return $userids;
}