Advertisement
Guest User

Untitled

a guest
Mar 25th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2. // Custom profile search
  3. function custom_profile_search()
  4. {
  5.     global $wpdb, $bp;
  6.    
  7.     $userids = array();
  8.     $search_fields_id = array(4, 5, 8, 65, 106, 117, 118, 119, 122, 244, 245, 264, 265);
  9.     $search_quote = trim($_POST['search_quote']);
  10.     $allowed_users_ids = array();
  11.     $options = get_option('contributors_list');
  12.  
  13.     if ($options && count($options) > 0)
  14.         foreach ($options as $allowed_user_id => $value)
  15.             $allowed_users_ids[] = $allowed_user_id;
  16.    
  17.     if ($_POST['custom_profile_search'] != true && $search_quote == "")
  18.     {
  19.         $userids = $allowed_users_ids;
  20.     }
  21.     else
  22.     {
  23.         if (bp_has_profile('hide_empty_fields=0')):
  24.             while (bp_profile_groups()): bp_the_profile_group();
  25.                 while (bp_profile_fields()): bp_the_profile_field();
  26.  
  27.                     $id = bp_get_the_profile_field_id();
  28.  
  29.                     if (!in_array($id, $search_fields_id))
  30.                         continue;
  31.  
  32.                     $sql = "SELECT user_id
  33.                             FROM {$bp->profile->table_name_data}
  34.                             WHERE field_id = $id";
  35.  
  36.                     $sql .= " AND value LIKE '%%$search_quote%%'";
  37.  
  38.                     $found = $wpdb->get_results($wpdb->prepare($sql));
  39.  
  40.                     if (count($found) > 0)
  41.                     {
  42.                         foreach ($found as $user)
  43.                         {
  44.                             $userid = $user->user_id;
  45.  
  46.                             if (!in_array($userid, $allowed_users_ids))
  47.                                 continue;
  48.  
  49.                             if (!in_array($userid, $userids))
  50.                                 $userids[] = $userid;
  51.                         }
  52.                     }
  53.                 endwhile;
  54.             endwhile;
  55.         endif;
  56.     }
  57.    
  58.     return $userids;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement