Changeset 6615 for trunk/wp-admin/includes/user.php
- Timestamp:
- 01/14/2008 09:55:17 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/user.php
r6354 r6615 282 282 } 283 283 284 // WP_User_Search class 285 // by Mark Jaquith 286 287 if ( !class_exists('WP_User_Search') ) : 288 class WP_User_Search { 289 var $results; 290 var $search_term; 291 var $page; 292 var $raw_page; 293 var $users_per_page = 50; 294 var $first_user; 295 var $last_user; 296 var $query_limit; 297 var $query_from_where; 298 var $total_users_for_query = 0; 299 var $too_many_total_users = false; 300 var $search_errors; 301 302 function WP_User_Search ($search_term = '', $page = '') { // constructor 303 $this->search_term = $search_term; 304 $this->raw_page = ( '' == $page ) ? false : (int) $page; 305 $this->page = (int) ( '' == $page ) ? 1 : $page; 306 307 $this->prepare_query(); 308 $this->query(); 309 $this->prepare_vars_for_template_usage(); 310 $this->do_paging(); 311 } 312 313 function prepare_query() { 314 global $wpdb; 315 $this->first_user = ($this->page - 1) * $this->users_per_page; 316 $this->query_limit = 'LIMIT ' . $this->first_user . ',' . $this->users_per_page; 317 if ( $this->search_term ) { 318 $searches = array(); 319 $search_sql = 'AND ('; 320 foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col ) 321 $searches[] = $col . " LIKE '%$this->search_term%'"; 322 $search_sql .= implode(' OR ', $searches); 323 $search_sql .= ')'; 324 } 325 $this->query_from_where = "FROM $wpdb->users WHERE 1=1 $search_sql"; 326 327 } 328 329 function query() { 330 global $wpdb; 331 $this->results = $wpdb->get_col('SELECT ID ' . $this->query_from_where . $this->query_limit); 332 333 if ( $this->results ) 334 $this->total_users_for_query = $wpdb->get_var('SELECT COUNT(ID) ' . $this->query_from_where); // no limit 335 else 336 $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!')); 337 } 338 339 function prepare_vars_for_template_usage() { 340 $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone 341 } 342 343 function do_paging() { 344 if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results 345 $this->paging_text = paginate_links( array( 346 'total' => ceil($this->total_users_for_query / $this->users_per_page), 347 'current' => $this->page, 348 'prev_text' => __('« Previous Page'), 349 'next_text' => __('Next Page »'), 350 'base' => 'users.php?%_%', 351 'format' => 'userspage=%#%', 352 'add_args' => array( 'usersearch' => urlencode($this->search_term) ) 353 ) ); 354 } 355 } 356 357 function get_results() { 358 return (array) $this->results; 359 } 360 361 function page_links() { 362 echo $this->paging_text; 363 } 364 365 function results_are_paged() { 366 if ( $this->paging_text ) 367 return true; 368 return false; 369 } 370 371 function is_search() { 372 if ( $this->search_term ) 373 return true; 374 return false; 375 } 376 } 377 endif; 378 284 379 ?>
Note: See TracChangeset
for help on using the changeset viewer.