Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BP_Custom_User_Ids {
- private $custom_ids = array();
- public $friends_list;
- public function __construct($friend) {
- $this->friends_list = $friend;
- $this->custom_ids = $this->get_custom_ids();
- add_action( 'bp_pre_user_query_construct', array( $this, 'custom_members_query' ), 1, 1 );
- add_filter( 'bp_get_total_member_count', array( $this, 'custom_members_count' ), 1, 1 );
- }
- private function get_custom_ids() {
- global $wpdb;
- $f_id = $this->friends_list;
- $query = " SELECT user_id "
- . " FROM " . $wpdb->prefix . "bp_xprofile_data "
- . " WHERE user_id IN({$f_id}) "
- . " GROUP BY user_id "
- . " UNION "
- . " SELECT user_id "
- . " FROM " . $wpdb->prefix . "bp_xprofile_data "
- . " WHERE user_id NOT IN({$f_id}) "
- . " GROUP BY user_id ";
- // collection based on an xprofile field
- $custom_ids_list = $wpdb->get_col( $query );
- if (!empty( $custom_ids_list )) {
- $custom_ids_str = implode(",", $custom_ids_list);
- return $custom_ids_str;
- }
- else
- return '';
- }
- function custom_members_query( $query_array ) {
- $query_array->query_vars['user_ids'] = $this->custom_ids;
- //in case there are other items like widgets using the members loop on the members page
- remove_action( 'bp_pre_user_query_construct', array( $this, 'custom_members_query' ), 1, 1 );
- }
- function custom_members_count ( $count ) {
- $new_count = count( $this->custom_ids );
- return $count - $new_count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment