[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-admin/includes/ -> class-wp-ms-users-list-table.php (source)

   1  <?php
   2  /**
   3   * Multisite Users List Table class.
   4   *
   5   * @package WordPress
   6   * @subpackage List_Table
   7   * @since 3.1.0
   8   * @access private
   9   */
  10  class WP_MS_Users_List_Table extends WP_List_Table {
  11  
  12  	function ajax_user_can() {
  13          return current_user_can( 'manage_network_users' );
  14      }
  15  
  16  	function prepare_items() {
  17          global $usersearch, $role, $wpdb, $mode;
  18  
  19          $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
  20  
  21          $users_per_page = $this->get_items_per_page( 'users_network_per_page' );
  22  
  23          $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
  24  
  25          $paged = $this->get_pagenum();
  26  
  27          $args = array(
  28              'number' => $users_per_page,
  29              'offset' => ( $paged-1 ) * $users_per_page,
  30              'search' => $usersearch,
  31              'blog_id' => 0,
  32              'fields' => 'all_with_meta'
  33          );
  34  
  35          $args['search'] = ltrim($args['search'], '*');
  36  
  37          if ( $role == 'super' ) {
  38              $logins = implode( "', '", get_super_admins() );
  39              $args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
  40          }
  41  
  42          // If the network is large and a search is not being performed, show only the latest users with no paging in order
  43          // to avoid expensive count queries.
  44          if ( !$usersearch && ( get_blog_count() >= 10000 ) ) {
  45              if ( !isset($_REQUEST['orderby']) )
  46                  $_GET['orderby'] = $_REQUEST['orderby'] = 'id';
  47              if ( !isset($_REQUEST['order']) )
  48                  $_GET['order'] = $_REQUEST['order'] = 'DESC';
  49              $args['count_total'] = false;
  50          }
  51  
  52          if ( isset( $_REQUEST['orderby'] ) )
  53              $args['orderby'] = $_REQUEST['orderby'];
  54  
  55          if ( isset( $_REQUEST['order'] ) )
  56              $args['order'] = $_REQUEST['order'];
  57  
  58          $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
  59  
  60          // Query the user IDs for this page
  61          $wp_user_search = new WP_User_Query( $args );
  62  
  63          $this->items = $wp_user_search->get_results();
  64  
  65          $this->set_pagination_args( array(
  66              'total_items' => $wp_user_search->get_total(),
  67              'per_page' => $users_per_page,
  68          ) );
  69      }
  70  
  71  	function get_bulk_actions() {
  72          $actions = array();
  73          if ( current_user_can( 'delete_users' ) )
  74              $actions['delete'] = __( 'Delete' );
  75          $actions['spam'] = _x( 'Mark as Spam', 'user' );
  76          $actions['notspam'] = _x( 'Not Spam', 'user' );
  77  
  78          return $actions;
  79      }
  80  
  81  	function no_items() {
  82          _e( 'No users found.' );
  83      }
  84  
  85  	function get_views() {
  86          global $wp_roles, $role;
  87  
  88          $total_users = get_user_count();
  89          $super_admins = get_super_admins();
  90          $total_admins = count( $super_admins );
  91  
  92          $current_role = false;
  93          $class = $role != 'super' ? ' class="current"' : '';
  94          $role_links = array();
  95          $role_links['all'] = "<a href='" . network_admin_url('users.php') . "'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
  96          $class = $role == 'super' ? ' class="current"' : '';
  97          $role_links['super'] = "<a href='" . network_admin_url('users.php?role=super') . "'$class>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>';
  98  
  99          return $role_links;
 100      }
 101  
 102  	function pagination( $which ) {
 103          global $mode;
 104  
 105          parent::pagination ( $which );
 106  
 107          if ( 'top' == $which )
 108              $this->view_switcher( $mode );
 109      }
 110  
 111  	function get_columns() {
 112          $users_columns = array(
 113              'cb'         => '<input type="checkbox" />',
 114              'username'   => __( 'Username' ),
 115              'name'       => __( 'Name' ),
 116              'email'      => __( 'E-mail' ),
 117              'registered' => _x( 'Registered', 'user' ),
 118              'blogs'      => __( 'Sites' )
 119          );
 120          $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
 121  
 122          return $users_columns;
 123      }
 124  
 125  	function get_sortable_columns() {
 126          return array(
 127              'username'   => 'login',
 128              'name'       => 'name',
 129              'email'      => 'email',
 130              'registered' => 'id',
 131          );
 132      }
 133  
 134  	function display_rows() {
 135          global $current_site, $mode;
 136  
 137          $alt = '';
 138          $super_admins = get_super_admins();
 139          foreach ( $this->items as $user ) {
 140              $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
 141  
 142              $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
 143  
 144              foreach ( $status_list as $status => $col ) {
 145                  if ( $user->$status )
 146                      $alt .= " $col";
 147              }
 148  
 149              ?>
 150              <tr class="<?php echo $alt; ?>">
 151              <?php
 152  
 153              list( $columns, $hidden ) = $this->get_column_info();
 154  
 155              foreach ( $columns as $column_name => $column_display_name ) :
 156                  $class = "class='$column_name column-$column_name'";
 157  
 158                  $style = '';
 159                  if ( in_array( $column_name, $hidden ) )
 160                      $style = ' style="display:none;"';
 161  
 162                  $attributes = "$class$style";
 163  
 164  
 165                  switch ( $column_name ) {
 166                      case 'cb': ?>
 167                          <th scope="row" class="check-column">
 168                              <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
 169                          </th>
 170                      <?php
 171                      break;
 172  
 173                      case 'username':
 174                          $avatar    = get_avatar( $user->user_email, 32 );
 175                          if ( get_current_user_id() == $user->ID ) {
 176                              $edit_link = esc_url( network_admin_url( 'profile.php' ) );
 177                          } else {
 178                              $edit_link = esc_url( network_admin_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), 'user-edit.php?user_id=' . $user->ID ) ) );
 179                          }
 180  
 181                          echo "<td $attributes>"; ?>
 182                              <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo stripslashes( $user->user_login ); ?></a><?php
 183                              if ( in_array( $user->user_login, $super_admins ) )
 184                                  echo ' - ' . __( 'Super Admin' );
 185                              ?></strong>
 186                              <br/>
 187                              <?php
 188                                  $actions = array();
 189                                  $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
 190  
 191                                  if ( current_user_can( 'delete_user', $user->ID) && ! in_array( $user->user_login, $super_admins ) ) {
 192                                      $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'edit.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
 193                                  }
 194  
 195                                  echo $this->row_actions( $actions );
 196                              ?>
 197                          </td>
 198                      <?php
 199                      break;
 200  
 201                      case 'name':
 202                          echo "<td $attributes>$user->first_name $user->last_name</td>";
 203                      break;
 204  
 205                      case 'email':
 206                          echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
 207                      break;
 208  
 209                      case 'registered':
 210                          if ( 'list' == $mode )
 211                              $date = 'Y/m/d';
 212                          else
 213                              $date = 'Y/m/d \<\b\r \/\> g:i:s a';
 214  
 215                          echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
 216                      break;
 217  
 218                      case 'blogs':
 219                          $blogs = get_blogs_of_user( $user->ID, true );
 220                          echo "<td $attributes>";
 221                              if ( is_array( $blogs ) ) {
 222                                  foreach ( (array) $blogs as $key => $val ) {
 223                                      if ( !can_edit_network( $val->site_id ) )
 224                                          continue;
 225  
 226                                      $path    = ( $val->path == '/' ) ? '' : $val->path;
 227                                      echo '<span class="site-' . $val->site_id . '" >';
 228                                      echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>';
 229                                      echo ' <small class="row-actions">';
 230                                      $actions = array();
 231                                      $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
 232  
 233                                      $class = '';
 234                                      if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
 235                                          $class .= 'site-spammed ';
 236                                      if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 )
 237                                          $class .= 'site-mature ';
 238                                      if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 )
 239                                          $class .= 'site-deleted ';
 240                                      if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 )
 241                                          $class .= 'site-archived ';
 242  
 243                                      $actions['view'] = '<a class="' . $class . '" href="' .  esc_url( get_home_url( $val->userblog_id ) )  . '">' . __( 'View' ) . '</a>';
 244  
 245                                      $actions = apply_filters('ms_user_list_site_actions', $actions, $val->userblog_id);
 246  
 247                                      $i=0;
 248                                      $action_count = count( $actions );
 249                                      foreach ( $actions as $action => $link ) {
 250                                          ++$i;
 251                                          ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
 252                                          echo "<span class='$action'>$link$sep</span>";
 253                                      }
 254                                      echo '</small></span><br/>';
 255                                  }
 256                              }
 257                              ?>
 258                          </td>
 259                      <?php
 260                      break;
 261  
 262                      default:
 263                          echo "<td $attributes>";
 264                          echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
 265                          echo "</td>";
 266                      break;
 267                  }
 268              endforeach
 269              ?>
 270              </tr>
 271              <?php
 272          }
 273      }
 274  }
 275  
 276  ?>


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting