M_Member_Search

The Membership 2 M Member Search class.

Defined (1)

The class is defined in the following location(s).

/app_old/membershipincludes/classes/class.membersearch.php  
  1. class M_Member_Search extends WP_User_Search { 
  2.  
  3. var $sub_id = false; 
  4. var $level_id = false; 
  5. var $active = false; 
  6.  
  7. function M_Member_Search($search_term = '', $page = '', $sub_id = false, $level_id = false, $active = false) { 
  8. $this->search_term = $search_term; 
  9. $this->raw_page = ( '' == $page ) ? false : (int) $page; 
  10. $this->page = (int) ( '' == $page ) ? 1 : $page; 
  11.  
  12. if(!empty($sub_id)) { 
  13. $this->sub_id = $sub_id; 
  14.  
  15. if(!empty($level_id)) { 
  16. $this->level_id = $level_id; 
  17.  
  18. if(!empty($active)) { 
  19. $this->active = $active; 
  20.  
  21. $this->prepare_query(); 
  22. $this->query(); 
  23. $this->prepare_vars_for_template_usage(); 
  24. $this->do_paging(); 
  25.  
  26. function do_paging() { 
  27. if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results 
  28. $args = array(); 
  29. if( ! empty($this->search_term) ) { 
  30. $args['s'] = urlencode($this->search_term); 
  31.  
  32. if( ! empty($this->role) ) { 
  33. $args['role'] = urlencode($this->role); 
  34. if( ! empty($this->sub_id) ) { 
  35. $args['sub_op'] = urlencode($this->sub_id); 
  36. $args['doactionsub'] = 'Filter'; 
  37. if( ! empty($this->level_id) ) { 
  38. $args['level_op'] = urlencode($this->level_id); 
  39. $args['doactionlevel'] = 'Filter'; 
  40.  
  41.  
  42. $this->paging_text = paginate_links( array( 
  43. 'total' => ceil($this->total_users_for_query / $this->users_per_page),  
  44. 'current' => $this->page,  
  45. 'base' => 'admin.php?page=membershipmembers&%_%',  
  46. 'format' => 'userspage=%#%',  
  47. 'add_args' => $args 
  48. ) ); 
  49. if ( $this->paging_text ) { 
  50. $this->paging_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s', 'membership' ) . '</span>%s',  
  51. number_format_i18n( ( $this->page - 1 ) * $this->users_per_page + 1 ),  
  52. number_format_i18n( min( $this->page * $this->users_per_page, $this->total_users_for_query ) ),  
  53. number_format_i18n( $this->total_users_for_query ),  
  54. $this->paging_text 
  55. ); 
  56.  
  57. function prepare_query() { 
  58.  
  59.  
  60. global $wpdb, $wp_version; 
  61.  
  62. $this->first_user = ($this->page - 1) * $this->users_per_page; 
  63.  
  64. $this->query_limit = $wpdb->prepare(" LIMIT %d, %d", $this->first_user, $this->users_per_page); 
  65. $this->query_orderby = ' ORDER BY user_login'; 
  66.  
  67. $search_sql = ''; 
  68.  
  69. if ( $this->search_term ) { 
  70. $searches = array(); 
  71. $search_sql = 'AND ('; 
  72. foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col ) 
  73. $searches[] = $col . " LIKE '%$this->search_term%'"; 
  74. $search_sql .= implode(' OR ', $searches); 
  75. $search_sql .= ')'; 
  76.  
  77. // The following code changes in WP3 and above 
  78.  
  79. // We are on version 3.0 or above 
  80. $this->query_from = " FROM $wpdb->users"; 
  81. $this->query_where = " WHERE 1=1 $search_sql"; 
  82.  
  83. if ( $this->role ) { 
  84. $this->query_from .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id"; 
  85. $this->query_where .= $wpdb->prepare(" AND $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $this->role . '%'); 
  86. } elseif ( is_multisite() ) { 
  87. $level_key = $wpdb->prefix . 'capabilities'; // wpmu site admins don't have user_levels 
  88. $this->query_from .= ", $wpdb->usermeta"; 
  89. $this->query_where .= " AND $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'"; 
  90.  
  91.  
  92. if( $this->sub_id ) { 
  93. $sql = $wpdb->prepare( "SELECT user_id FROM " . membership_db_prefix($wpdb, "membership_relationships") . " WHERE sub_id = %d", $this->sub_id ); 
  94.  
  95. $subs = $wpdb->get_col( $sql ); 
  96.  
  97. if(!empty($subs)) { 
  98. $this->query_where .= " AND {$wpdb->users}.ID IN (" . implode(', ', $subs) . ")"; 
  99. // wp 2.9.2 and lower 
  100. $this->query_from_where .= " AND {$wpdb->users}.ID IN (" . implode(', ', $subs) . ")"; 
  101. } else { 
  102. $this->query_where .= " AND {$wpdb->users}.ID IN (0)"; 
  103. // wp 2.9.2 and lower 
  104. $this->query_from_where .= " AND {$wpdb->users}.ID IN (0)"; 
  105.  
  106. if( $this->level_id ) { 
  107. $sql = $wpdb->prepare( "SELECT user_id FROM " . membership_db_prefix($wpdb, "membership_relationships") . " WHERE level_id = %d", $this->level_id ); 
  108.  
  109. $levels = $wpdb->get_col( $sql ); 
  110.  
  111. if(!empty($levels)) { 
  112. $this->query_where .= " AND {$wpdb->users}.ID IN (" . implode(', ', $levels) . ")"; 
  113. // wp 2.9.2 and lower 
  114. $this->query_from_where .= " AND {$wpdb->users}.ID IN (" . implode(', ', $levels) . ")"; 
  115. } else { 
  116. $this->query_where .= " AND {$wpdb->users}.ID IN (0)"; 
  117. // wp 2.9.2 and lower 
  118. $this->query_from_where .= " AND {$wpdb->users}.ID IN (0)"; 
  119.  
  120.  
  121. if($this->active) { 
  122. $sql = $wpdb->prepare( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE meta_key = '" . membership_db_prefix($wpdb, 'membership_active', false) . "' AND meta_value = %s", 'no' ); 
  123. $actives = $wpdb->get_col( $sql ); 
  124.  
  125. if(!empty($actives)) { 
  126. if($this->active == 'yes') { 
  127. $this->query_where .= " AND {$wpdb->users}.ID NOT IN (" . implode(', ', $actives) . ")"; 
  128. // wp 2.9.2 and lower 
  129. $this->query_from_where .= " AND {$wpdb->users}.ID NOT IN (" . implode(', ', $actives) . ")"; 
  130. } else { 
  131. // no 
  132. $this->query_where .= " AND {$wpdb->users}.ID IN (" . implode(', ', $actives) . ")"; 
  133. // wp 2.9.2 and lower 
  134. $this->query_from_where .= " AND {$wpdb->users}.ID IN (" . implode(', ', $actives) . ")"; 
  135. } else { 
  136. if($this->active == 'yes') { 
  137. $this->query_where .= " AND {$wpdb->users}.ID NOT IN (0)"; 
  138. // wp 2.9.2 and lower 
  139. $this->query_from_where .= " AND {$wpdb->users}.ID NOT IN (0)"; 
  140. } else { 
  141. // no 
  142. $this->query_where .= " AND {$wpdb->users}.ID IN (0)"; 
  143. // wp 2.9.2 and lower 
  144. $this->query_from_where .= " AND {$wpdb->users}.ID IN (0)"; 
  145.  
  146. do_action_ref_array( 'pre_user_search', array( &$this ) ); 
  147.  
  148.