Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1.  
  2. class BP_Custom_User_Ids {
  3.  
  4. private $custom_ids = array();
  5.  
  6. public function __construct() {
  7.  
  8. $this->custom_ids = $this->get_custom_ids();
  9.  
  10. add_action( 'bp_pre_user_query_construct', array( $this, 'custom_members_query' ), 1, 1 );
  11. add_filter( 'bp_get_total_member_count', array( $this, 'custom_members_count' ), 1, 1 );
  12.  
  13. }
  14.  
  15. private function get_custom_ids() {
  16. global $wpdb;
  17.  
  18. //figure out if the logged-in user is male or female
  19. $sex = xprofile_get_field_data( 852, bp_loggedin_user_id() );
  20.  
  21. if ( $sex == 'Muslim' )
  22. $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 852 AND value = 'Muslima'";
  23. else
  24. $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 852 AND value = 'Muslim'";
  25.  
  26.  
  27. $custom_ids = $wpdb->get_col( $query );
  28.  
  29.  
  30. return $custom_ids;
  31. }
  32.  
  33. function custom_members_query( $query_array ) {
  34.  
  35. $query_array->query_vars['include'] = $this->custom_ids;
  36.  
  37. }
  38.  
  39. function custom_members_count ( $count ) {
  40.  
  41. $new_count = count( $this->custom_ids );
  42. return $new_count;
  43.  
  44. }
  45. }
  46.  
  47. function custom_user_ids( ) {
  48.  
  49. new BP_Custom_User_Ids ();
  50.  
  51. }
  52.  
  53. add_action( 'bp_before_directory_members', 'custom_user_ids' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement