Guest User

BP_custom

a guest
Jun 7th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. class BP_Custom_User_Ids {
  2.  
  3.     private $custom_ids = array();
  4.     public $friends_list;
  5.  
  6.     public function __construct($friend) {
  7.         $this->friends_list = $friend;
  8.         $this->custom_ids = $this->get_custom_ids();
  9.         add_action( 'bp_pre_user_query_construct',  array( $this, 'custom_members_query' ), 1, 1 );
  10.         add_filter( 'bp_get_total_member_count',    array( $this, 'custom_members_count' ), 1, 1 );
  11.     }
  12.  
  13.     private function get_custom_ids() {
  14.         global $wpdb;
  15.         $f_id =  $this->friends_list;
  16.         $query =   " SELECT user_id  "
  17.                    . " FROM " . $wpdb->prefix  . "bp_xprofile_data "
  18.                    . " WHERE user_id IN({$f_id}) "
  19.                    . " GROUP BY user_id "
  20.                    . " UNION "
  21.                    . " SELECT user_id  "
  22.                    . " FROM " . $wpdb->prefix  . "bp_xprofile_data "
  23.                    . " WHERE user_id NOT IN({$f_id}) "
  24.                    . " GROUP BY user_id ";
  25.  
  26.         // collection based on an xprofile field
  27.         $custom_ids_list = $wpdb->get_col( $query );
  28.         if (!empty( $custom_ids_list )) {
  29.             $custom_ids_str =  implode(",", $custom_ids_list);
  30.             return $custom_ids_str;
  31.         }
  32.         else
  33.             return '';
  34.     }
  35.  
  36.     function custom_members_query( $query_array ) {
  37.  
  38.         $query_array->query_vars['user_ids'] = $this->custom_ids;
  39.  
  40.         //in case there are other items like widgets using the members loop on the members page
  41.         remove_action( 'bp_pre_user_query_construct', array( $this, 'custom_members_query' ), 1, 1 );
  42.  
  43.     }
  44.  
  45.     function custom_members_count ( $count ) {
  46.  
  47.         $new_count = count( $this->custom_ids );
  48.         return $count - $new_count;
  49.  
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment