Changeset 15748
- Timestamp:
- 10/07/2010 08:13:11 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/deprecated.php
r15653 r15748 289 289 } 290 290 291 if ( !class_exists('WP_User_Search') ) : 292 /** 293 * WordPress User Search class. 294 * 295 * @since 2.1 296 * @deprecated 3.1.0 297 */ 298 class WP_User_Search { 299 300 /** 301 * {@internal Missing Description}} 302 * 303 * @since unknown 304 * @access private 305 * @var unknown_type 306 */ 307 var $results; 308 309 /** 310 * {@internal Missing Description}} 311 * 312 * @since unknown 313 * @access private 314 * @var unknown_type 315 */ 316 var $search_term; 317 318 /** 319 * Page number. 320 * 321 * @since unknown 322 * @access private 323 * @var int 324 */ 325 var $page; 326 327 /** 328 * Role name that users have. 329 * 330 * @since unknown 331 * @access private 332 * @var string 333 */ 334 var $role; 335 336 /** 337 * Raw page number. 338 * 339 * @since unknown 340 * @access private 341 * @var int|bool 342 */ 343 var $raw_page; 344 345 /** 346 * Amount of users to display per page. 347 * 348 * @since unknown 349 * @access public 350 * @var int 351 */ 352 var $users_per_page = 50; 353 354 /** 355 * {@internal Missing Description}} 356 * 357 * @since unknown 358 * @access private 359 * @var unknown_type 360 */ 361 var $first_user; 362 363 /** 364 * {@internal Missing Description}} 365 * 366 * @since unknown 367 * @access private 368 * @var int 369 */ 370 var $last_user; 371 372 /** 373 * {@internal Missing Description}} 374 * 375 * @since unknown 376 * @access private 377 * @var string 378 */ 379 var $query_limit; 380 381 /** 382 * {@internal Missing Description}} 383 * 384 * @since 3.0.0 385 * @access private 386 * @var string 387 */ 388 var $query_orderby; 389 390 /** 391 * {@internal Missing Description}} 392 * 393 * @since 3.0.0 394 * @access private 395 * @var string 396 */ 397 var $query_from; 398 399 /** 400 * {@internal Missing Description}} 401 * 402 * @since 3.0.0 403 * @access private 404 * @var string 405 */ 406 var $query_where; 407 408 /** 409 * {@internal Missing Description}} 410 * 411 * @since unknown 412 * @access private 413 * @var int 414 */ 415 var $total_users_for_query = 0; 416 417 /** 418 * {@internal Missing Description}} 419 * 420 * @since unknown 421 * @access private 422 * @var bool 423 */ 424 var $too_many_total_users = false; 425 426 /** 427 * {@internal Missing Description}} 428 * 429 * @since unknown 430 * @access private 431 * @var unknown_type 432 */ 433 var $search_errors; 434 435 /** 436 * {@internal Missing Description}} 437 * 438 * @since unknown 439 * @access private 440 * @var unknown_type 441 */ 442 var $paging_text; 443 444 /** 445 * PHP4 Constructor - Sets up the object properties. 446 * 447 * @since unknown 448 * 449 * @param string $search_term Search terms string. 450 * @param int $page Optional. Page ID. 451 * @param string $role Role name. 452 * @return WP_User_Search 453 */ 454 function WP_User_Search ($search_term = '', $page = '', $role = '') { 455 _deprecated_function( __FUNCTION__, '3.1', 'WP_User_Query' ); 456 457 $this->search_term = $search_term; 458 $this->raw_page = ( '' == $page ) ? false : (int) $page; 459 $this->page = (int) ( '' == $page ) ? 1 : $page; 460 $this->role = $role; 461 462 $this->prepare_query(); 463 $this->query(); 464 $this->prepare_vars_for_template_usage(); 465 $this->do_paging(); 466 } 467 468 /** 469 * {@internal Missing Short Description}} 470 * 471 * {@internal Missing Long Description}} 472 * 473 * @since unknown 474 * @access public 475 */ 476 function prepare_query() { 477 global $wpdb; 478 $this->first_user = ($this->page - 1) * $this->users_per_page; 479 480 $this->query_limit = $wpdb->prepare(" LIMIT %d, %d", $this->first_user, $this->users_per_page); 481 $this->query_orderby = ' ORDER BY user_login'; 482 483 $search_sql = ''; 484 if ( $this->search_term ) { 485 $searches = array(); 486 $search_sql = 'AND ('; 487 foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col ) 488 $searches[] = $col . " LIKE '%$this->search_term%'"; 489 $search_sql .= implode(' OR ', $searches); 490 $search_sql .= ')'; 491 } 492 493 $this->query_from = " FROM $wpdb->users"; 494 $this->query_where = " WHERE 1=1 $search_sql"; 495 496 if ( $this->role ) { 497 $this->query_from .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id"; 498 $this->query_where .= $wpdb->prepare(" AND $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $this->role . '%'); 499 } elseif ( is_multisite() ) { 500 $level_key = $wpdb->prefix . 'capabilities'; // wpmu site admins don't have user_levels 501 $this->query_from .= ", $wpdb->usermeta"; 502 $this->query_where .= " AND $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'"; 503 } 504 505 do_action_ref_array( 'pre_user_search', array( &$this ) ); 506 } 507 508 /** 509 * {@internal Missing Short Description}} 510 * 511 * {@internal Missing Long Description}} 512 * 513 * @since unknown 514 * @access public 515 */ 516 function query() { 517 global $wpdb; 518 519 $this->results = $wpdb->get_col("SELECT DISTINCT($wpdb->users.ID)" . $this->query_from . $this->query_where . $this->query_orderby . $this->query_limit); 520 521 if ( $this->results ) 522 $this->total_users_for_query = $wpdb->get_var("SELECT COUNT(DISTINCT($wpdb->users.ID))" . $this->query_from . $this->query_where); // no limit 523 else 524 $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!')); 525 } 526 527 /** 528 * {@internal Missing Short Description}} 529 * 530 * {@internal Missing Long Description}} 531 * 532 * @since unknown 533 * @access public 534 */ 535 function prepare_vars_for_template_usage() { 536 $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone 537 } 538 539 /** 540 * {@internal Missing Short Description}} 541 * 542 * {@internal Missing Long Description}} 543 * 544 * @since unknown 545 * @access public 546 */ 547 function do_paging() { 548 if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results 549 $args = array(); 550 if( ! empty($this->search_term) ) 551 $args['usersearch'] = urlencode($this->search_term); 552 if( ! empty($this->role) ) 553 $args['role'] = urlencode($this->role); 554 555 $this->paging_text = paginate_links( array( 556 'total' => ceil($this->total_users_for_query / $this->users_per_page), 557 'current' => $this->page, 558 'base' => 'users.php?%_%', 559 'format' => 'userspage=%#%', 560 'add_args' => $args 561 ) ); 562 if ( $this->paging_text ) { 563 $this->paging_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s', 564 number_format_i18n( ( $this->page - 1 ) * $this->users_per_page + 1 ), 565 number_format_i18n( min( $this->page * $this->users_per_page, $this->total_users_for_query ) ), 566 number_format_i18n( $this->total_users_for_query ), 567 $this->paging_text 568 ); 569 } 570 } 571 } 572 573 /** 574 * {@internal Missing Short Description}} 575 * 576 * {@internal Missing Long Description}} 577 * 578 * @since unknown 579 * @access public 580 * 581 * @return unknown 582 */ 583 function get_results() { 584 return (array) $this->results; 585 } 586 587 /** 588 * Displaying paging text. 589 * 590 * @see do_paging() Builds paging text. 591 * 592 * @since unknown 593 * @access public 594 */ 595 function page_links() { 596 echo $this->paging_text; 597 } 598 599 /** 600 * Whether paging is enabled. 601 * 602 * @see do_paging() Builds paging text. 603 * 604 * @since unknown 605 * @access public 606 * 607 * @return bool 608 */ 609 function results_are_paged() { 610 if ( $this->paging_text ) 611 return true; 612 return false; 613 } 614 615 /** 616 * Whether there are search terms. 617 * 618 * @since unknown 619 * @access public 620 * 621 * @return bool 622 */ 623 function is_search() { 624 if ( $this->search_term ) 625 return true; 626 return false; 627 } 628 } 629 endif; 630 291 631 /** 292 632 * Retrieve editable posts from other users.
Note: See TracChangeset
for help on using the changeset viewer.