Guest User

Untitled

a guest
Mar 6th, 2016
125
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Remove seeing same gender*/
  2. class BP_Custom_User_Ids {
  3. private $custom_ids = array();
  4. public function __construct() {
  5. $this->custom_ids = $this->get_custom_ids();
  6.  
  7. add_action( 'bp_pre_user_query_construct', array( $this,'custom_members_query' ), 1, 1 );
  8. add_filter( 'bp_get_total_member_count', array( $this, 'custom_members_count' ), 1, 1 );}
  9.  
  10. private function get_custom_ids() {
  11. global $wpdb;
  12.  
  13. // figure out if the logged-in user is male or female
  14. $sex = xprofile_get_field_data( 3, bp_loggedin_user_id() );
  15.  
  16. if ( $sex == 'Man' )
  17. $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 3 AND value = 'Woman'";
  18. else
  19. $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 3 AND value = 'Man'";
  20.  
  21. $custom_ids = $wpdb->get_col( $query );
  22. return $custom_ids;}
  23.  
  24. function custom_members_query( $query_array ) {
  25.  
  26. $query_array->query_vars['include'] = $this->custom_ids;}
  27.  
  28. function custom_members_count ( $count ) {
  29.  
  30. $new_count = count( $this->custom_ids );
  31. return $new_count;}
  32. }
  33.  
  34. function custom_user_ids( ) {
  35.  
  36. new BP_Custom_User_Ids ();}
  37.  
  38. add_action( 'bp_before_directory_members', 'custom_user_ids' );
RAW Paste Data