Changeset 6615 for trunk/wp-admin/users.php
- Timestamp:
- 01/14/2008 09:55:17 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/users.php
r6570 r6615 20 20 $redirect = 'users.php'; 21 21 } 22 23 24 // WP_User_Search class25 // by Mark Jaquith26 27 28 class WP_User_Search {29 var $results;30 var $search_term;31 var $page;32 var $raw_page;33 var $users_per_page = 50;34 var $first_user;35 var $last_user;36 var $query_limit;37 var $query_from_where;38 var $total_users_for_query = 0;39 var $too_many_total_users = false;40 var $search_errors;41 42 function WP_User_Search ($search_term = '', $page = '') { // constructor43 $this->search_term = $search_term;44 $this->raw_page = ( '' == $page ) ? false : (int) $page;45 $this->page = (int) ( '' == $page ) ? 1 : $page;46 47 $this->prepare_query();48 $this->query();49 $this->prepare_vars_for_template_usage();50 $this->do_paging();51 }52 53 function prepare_query() {54 global $wpdb;55 $this->first_user = ($this->page - 1) * $this->users_per_page;56 $this->query_limit = 'LIMIT ' . $this->first_user . ',' . $this->users_per_page;57 if ( $this->search_term ) {58 $searches = array();59 $search_sql = 'AND (';60 foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col )61 $searches[] = $col . " LIKE '%$this->search_term%'";62 $search_sql .= implode(' OR ', $searches);63 $search_sql .= ')';64 }65 $this->query_from_where = "FROM $wpdb->users WHERE 1=1 $search_sql";66 67 }68 69 function query() {70 global $wpdb;71 $this->results = $wpdb->get_col('SELECT ID ' . $this->query_from_where . $this->query_limit);72 73 if ( $this->results )74 $this->total_users_for_query = $wpdb->get_var('SELECT COUNT(ID) ' . $this->query_from_where); // no limit75 else76 $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!'));77 }78 79 function prepare_vars_for_template_usage() {80 $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone81 }82 83 function do_paging() {84 if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results85 $this->paging_text = paginate_links( array(86 'total' => ceil($this->total_users_for_query / $this->users_per_page),87 'current' => $this->page,88 'prev_text' => __('« Previous Page'),89 'next_text' => __('Next Page »'),90 'base' => 'users.php?%_%',91 'format' => 'userspage=%#%',92 'add_args' => array( 'usersearch' => urlencode($this->search_term) )93 ) );94 }95 }96 97 function get_results() {98 return (array) $this->results;99 }100 101 function page_links() {102 echo $this->paging_text;103 }104 105 function results_are_paged() {106 if ( $this->paging_text )107 return true;108 return false;109 }110 111 function is_search() {112 if ( $this->search_term )113 return true;114 return false;115 }116 }117 118 22 119 23 switch ($action) {
Note: See TracChangeset
for help on using the changeset viewer.