[ Index ]

PHP Cross Reference of WordPress 3.0 beta 1

[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/wp-admin/ -> ms-users.php (source)

   1  <?php
   2  require_once ( './admin.php' );
   3  
   4  if ( !is_multisite() )
   5      wp_die( __( 'Multisite support is not enabled.' ) );
   6  
   7  if ( ! current_user_can( 'manage_network_users' ) )
   8      wp_die( __( 'You do not have permission to access this page.' ) );
   9  
  10  $title = __( 'Users' );
  11  $parent_file = 'ms-admin.php';
  12  
  13  wp_enqueue_script( 'admin-forms' );
  14  
  15  require_once ( './admin-header.php' );
  16  
  17  if ( isset( $_GET['updated'] ) && $_GET['updated'] == 'true' && ! empty( $_GET['action'] ) ) {
  18      ?>
  19      <div id="message" class="updated fade"><p>
  20          <?php
  21          switch ( $_GET['action'] ) {
  22              case 'delete':
  23                  _e( 'User deleted.' );
  24              break;
  25              case 'all_spam':
  26                  _e( 'Users marked as spam.' );
  27              break;
  28              case 'all_notspam':
  29                  _e( 'Users removed from spam.' );
  30              break;
  31              case 'all_delete':
  32                  _e( 'Users deleted.' );
  33              break;
  34              case 'add':
  35                  _e( 'User added.' );
  36              break;
  37          }
  38          ?>
  39      </p></div>
  40      <?php
  41  }
  42  
  43      $pagenum = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 0;
  44      if ( empty( $pagenum ) )
  45          $pagenum = 1;
  46  
  47      $per_page = (int) get_user_option( 'ms_users_per_page' );
  48      if ( empty( $per_page ) || $per_page < 1 )
  49          $per_page = 15;
  50  
  51      $per_page = apply_filters( 'ms_users_per_page', $per_page );
  52  
  53      $s = isset( $_GET['s'] ) ? stripslashes( trim( $_GET[ 's' ] ) ) : '';
  54      $like_s = esc_sql( like_escape( $s ) );
  55  
  56      $query = "SELECT * FROM {$wpdb->users}";
  57  
  58      if ( !empty( $like_s ) ) {
  59          $query .= " WHERE user_login LIKE '%$like_s%' OR user_email LIKE '%$like_s%'";
  60      }
  61  
  62      $order_by = isset( $_GET['sortby'] ) ? $_GET['sortby'] : 'id';
  63      if ( $order_by == 'email' ) {
  64          $query .= ' ORDER BY user_email ';
  65      } elseif ( $order_by == 'login' ) {
  66          $query .= ' ORDER BY user_login ';
  67      } elseif ( $order_by == 'name' ) {
  68          $query .= ' ORDER BY display_name ';
  69      } elseif ( $order_by == 'registered' ) {
  70          $query .= ' ORDER BY user_registered ';
  71      } else {
  72          $order_by = 'id';
  73          $query .= ' ORDER BY ID ';
  74      }
  75  
  76      $order = ( isset( $_GET['order'] ) && 'DESC' == $_GET['order'] ) ? 'DESC' : 'ASC';
  77      $query .= $order;
  78  
  79      $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT(ID)', $query ) );
  80  
  81      $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page) . ", " . intval( $per_page );
  82  
  83      $user_list = $wpdb->get_results( $query, ARRAY_A );
  84  
  85      $num_pages = ceil( $total / $per_page );
  86      $page_links = paginate_links( array(
  87          'base' => add_query_arg( 'paged', '%#%' ),
  88          'format' => '',
  89          'prev_text' => __( '&laquo;' ),
  90          'next_text' => __( '&raquo;' ),
  91          'total' => $num_pages,
  92          'current' => $pagenum
  93      ));
  94  
  95      if ( empty( $_GET['mode'] ) )
  96          $mode = 'list';
  97      else
  98          $mode = esc_attr( $_GET['mode'] );
  99  
 100      ?>
 101      <div class="wrap">
 102      <?php screen_icon(); ?>
 103      <h2><?php esc_html_e( 'Users' ); ?>
 104      <a href="#form-add-user" class="button add-new-h2"><?php echo esc_html_x( 'Add New' , 'users'); ?></a>
 105      <?php
 106      if ( isset( $_GET['s'] ) && $_GET['s'] )
 107      printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
 108      ?>
 109      </h2>
 110  
 111      <form action="ms-users.php" method="get" class="search-form">
 112          <p class="search-box">
 113          <input type="text" name="s" value="<?php echo esc_attr( $s ); ?>" class="search-input" id="user-search-input" />
 114          <input type="submit" id="post-query-submit" value="<?php esc_attr_e( 'Search Users' ) ?>" class="button" />
 115          </p>
 116      </form>
 117  
 118      <form id="form-user-list" action='ms-edit.php?action=allusers' method='post'>
 119          <input type="hidden" name="mode" value="<?php echo esc_attr( $mode ); ?>" />
 120          <div class="tablenav">
 121              <div class="alignleft actions">
 122                  <select name="action">
 123                      <option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option>
 124                      <option value="delete"><?php _e( 'Delete' ); ?></option>
 125                      <option value="spam"><?php _e( 'Mark as Spam' ); ?></option>
 126                      <option value="notspam"><?php _e( 'Not Spam' ); ?></option>
 127                  </select>
 128                  <input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction" id="doaction" class="button-secondary action" />
 129                  <?php wp_nonce_field( 'bulk-ms-users' ); ?>
 130              </div>
 131  
 132              <?php if ( $page_links ) { ?>
 133              <div class="tablenav-pages">
 134              <?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
 135              number_format_i18n( ( $pagenum - 1 ) * $per_page + 1 ),
 136              number_format_i18n( min( $pagenum * $per_page, $num_pages ) ),
 137              number_format_i18n( $num_pages ),
 138              $page_links
 139              ); echo $page_links_text; ?>
 140              </div>
 141              <?php } ?>
 142  
 143              <div class="view-switch">
 144                  <a href="<?php echo esc_url( add_query_arg( 'mode', 'list', $_SERVER['REQUEST_URI'] ) ) ?>"><img <?php if ( 'list' == $mode ) echo 'class="current"'; ?> id="view-switch-list" src="<?php echo esc_url( includes_url( 'images/blank.gif' ) ); ?>" width="20" height="20" title="<?php _e( 'List View' ) ?>" alt="<?php _e( 'List View' ) ?>" /></a>
 145                  <a href="<?php echo esc_url( add_query_arg( 'mode', 'excerpt', $_SERVER['REQUEST_URI'] ) ) ?>"><img <?php if ( 'excerpt' == $mode ) echo 'class="current"'; ?> id="view-switch-excerpt" src="<?php echo esc_url( includes_url( 'images/blank.gif' ) ); ?>" width="20" height="20" title="<?php _e( 'Excerpt View' ) ?>" alt="<?php _e( 'Excerpt View' ) ?>" /></a>
 146              </div>
 147          </div>
 148          <div class="clear"></div>
 149  
 150          <?php
 151          // define the columns to display, the syntax is 'internal name' => 'display name'
 152          $users_columns = array(
 153              'id'           => __( 'ID' ),
 154              'login'      => __( 'Username' ),
 155              'name'       => __( 'Name' ),
 156              'email'      => __( 'E-mail' ),
 157              'registered' => __( 'Registered' ),
 158              'blogs'      => __( 'Sites' )
 159          );
 160          $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
 161          ?>
 162          <table class="widefat">
 163              <thead>
 164              <tr>
 165                  <th class="manage-column column-cb check-column" id="cb" scope="col">
 166                      <input type="checkbox" />
 167                  </th>
 168                  <?php
 169                  $col_url = '';
 170                  foreach($users_columns as $column_id => $column_display_name) {
 171                      $column_link = "<a href='";
 172                      $order2 = '';
 173                      if ( $order_by == $column_id )
 174                          $order2 = ( $order == 'DESC' ) ? 'ASC' : 'DESC';
 175  
 176                      $column_link .= esc_url( add_query_arg( array( 'order' => $order2, 'paged' => $pagenum, 'sortby' => $column_id ), remove_query_arg( array( 'action', 'updated' ), $_SERVER['REQUEST_URI'] ) ) );
 177                      $column_link .= "'>{$column_display_name}</a>";
 178                      $col_url .= '<th scope="col">' . ( $column_id == 'blogs' ? $column_display_name : $column_link ) . '</th>';
 179                  }
 180                  echo $col_url; ?>
 181              </tr>
 182              </thead>
 183              <tfoot>
 184              <tr>
 185                  <th class="manage-column column-cb check-column" id="cb" scope="col">
 186                      <input type="checkbox" />
 187                  </th>
 188                  <?php echo $col_url; ?>
 189              </tr>
 190              </tfoot>
 191              <tbody id="the-user-list" class="list:user">
 192              <?php if ( $user_list ) {
 193                  $class = '';
 194                  $super_admins = get_site_option( 'site_admins' );
 195                  foreach ( (array) $user_list as $user ) {
 196                      $class = ( 'alternate' == $class ) ? '' : 'alternate';
 197  
 198                      $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
 199  
 200                      foreach ( $status_list as $status => $col ) {
 201                          if ( $user[$status] )
 202                              $class = $col;
 203                      }
 204  
 205                      ?>
 206                      <tr class="<?php echo $class; ?>">
 207                      <?php
 208                      foreach( (array) $users_columns as $column_name=>$column_display_name ) :
 209                          switch( $column_name ) {
 210                              case 'id': ?>
 211                                  <th scope="row" class="check-column">
 212                                      <input type="checkbox" id="blog_<?php echo $user['ID'] ?>" name="allusers[]" value="<?php echo esc_attr( $user['ID'] ) ?>" />
 213                                  </th>
 214                                  <th valign="top" scope="row">
 215                                      <?php echo $user['ID'] ?>
 216                                  </th>
 217                              <?php
 218                              break;
 219  
 220                              case 'login':
 221                                  $avatar    = get_avatar( $user['user_email'], 32 );
 222                                  $edit_link = ( $current_user->ID == $user['ID'] ) ? 'profile.php' : 'user-edit.php?user_id=' . $user['ID'];
 223                                  ?>
 224                                  <td class="username column-username">
 225                                      <?php echo $avatar; ?><strong><a href="<?php echo esc_url( admin_url( $edit_link ) ); ?>" class="edit"><?php echo stripslashes( $user['user_login'] ); ?></a><?php
 226                                      if ( in_array( $user['user_login'], $super_admins ) )
 227                                          echo ' - ' . __( 'Super admin' );
 228                                      ?></strong>
 229                                      <br/>
 230                                      <div class="row-actions">
 231                                          <span class="edit"><a href="<?php echo esc_url( admin_url( $edit_link ) ); ?>"><?php _e( 'Edit' ); ?></a></span>
 232                                          <?php if ( ! in_array( $user['user_login'], $super_admins ) ) { ?>
 233                                          | <span class="delete"><a href="<?php echo $delete    = esc_url( admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'ms-edit.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user['ID'] ) ) ); ?>" class="delete"><?php _e( 'Delete' ); ?></a></span>
 234                                          <?php } ?>
 235                                      </div>
 236                                  </td>
 237                              <?php
 238                              break;
 239  
 240                              case 'name': ?>
 241                                  <td class="name column-name"><?php echo $user['display_name'] ?></td>
 242                              <?php
 243                              break;
 244  
 245                              case 'email': ?>
 246                                  <td class="email column-email"><a href="mailto:<?php echo $user['user_email'] ?>"><?php echo $user['user_email'] ?></a></td>
 247                              <?php
 248                              break;
 249  
 250                              case 'registered': 
 251                                  if ( 'list' == $mode )
 252                                      $date = 'Y/m/d';
 253                                  else
 254                                      $date = 'Y/m/d \<\b\r \/\> g:i:s a';
 255                              ?>
 256                                  <td><?php echo mysql2date( __( $date ), $user['user_registered'] ); ?></td>
 257                              <?php
 258                              break;
 259  
 260                              case 'blogs':
 261                                  $blogs = get_blogs_of_user( $user['ID'], true );
 262                                  ?>
 263                                  <td>
 264                                      <?php
 265                                      if ( is_array( $blogs ) ) {
 266                                          foreach ( (array) $blogs as $key => $val ) {
 267                                              $path    = ( $val->path == '/' ) ? '' : $val->path;
 268                                              echo '<a href="'. esc_url( admin_url( 'ms-sites.php?action=editblog&amp;id=' . $val->userblog_id  ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>';
 269                                              echo ' <small class="row-actions">';
 270  
 271                                              // Edit
 272                                              echo '<a href="'. esc_url( admin_url( 'ms-sites.php?action=editblog&amp;id=' . $val->userblog_id  ) ) .'">' . __( 'Edit' ) . '</a> | ';
 273  
 274                                              // View
 275                                              echo '<a ';
 276                                              if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
 277                                                  echo 'style="background-color: #faa" ';
 278                                              echo 'href="' .  esc_url( get_home_url( $val->userblog_id ) )  . '">' . __( 'View' ) . '</a>';
 279                                              
 280                                              echo '</small><br />';
 281                                          }
 282                                      }
 283                                      ?>
 284                                  </td>
 285                              <?php
 286                              break;
 287  
 288                              default: ?>
 289                                  <td><?php do_action( 'manage_users_custom_column', $column_name, $user['ID'] ); ?></td>
 290                              <?php
 291                              break;
 292                          }
 293                      endforeach
 294                      ?>
 295                      </tr>
 296                      <?php
 297                  }
 298              } else {
 299              ?>
 300                  <tr>
 301                      <td colspan="<?php echo (int) count($users_columns); ?>"><?php _e( 'No users found.' ) ?></td>
 302                  </tr>
 303                  <?php
 304              } // end if ($users)
 305              ?>
 306              </tbody>
 307          </table>
 308  
 309          <div class="tablenav">
 310              <?php
 311              if ( $page_links )
 312                  echo "<div class='tablenav-pages'>$page_links_text</div>";
 313              ?>
 314  
 315              <div class="alignleft actions">
 316                  <select name="action2">
 317                      <option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option>
 318                      <option value="delete"><?php _e( 'Delete' ); ?></option>
 319                      <option value="spam"><?php _e( 'Mark as Spam' ); ?></option>
 320                      <option value="notspam"><?php _e( 'Not Spam' ); ?></option>
 321                  </select>
 322                  <input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
 323              </div>
 324              <br class="clear" />
 325          </div>
 326  
 327          </form>
 328          </div>
 329  
 330  <?php
 331  if ( apply_filters( 'show_adduser_fields', true ) ) :
 332  ?>
 333  <div class="wrap">
 334      <h2><?php _e( 'Add user' ) ?></h2>
 335      <form action="ms-edit.php?action=adduser" method="post" id="form-add-user">
 336      <table class="form-table">
 337          <tr class="form-field form-required">
 338              <th scope="row"><?php _e( 'Username' ) ?></th>
 339              <td><input type="text" class="regular-text" name="user[username]" /></td>
 340          </tr>
 341          <tr class="form-field form-required">
 342              <th scope="row"><?php _e( 'Email' ) ?></th>
 343              <td><input type="text" class="regular-text" name="user[email]" /></td>
 344          </tr>
 345          <tr class="form-field">
 346              <td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td>
 347          </tr>
 348      </table>
 349      <p class="submit">
 350          <?php wp_nonce_field( 'add-user' ) ?>
 351          <input class="button" type="submit" value="<?php esc_attr_e( 'Add user' ) ?>" /></p>
 352      </form>
 353  </div>
 354  <?php endif; ?>
 355  
 356  <?php include ( './admin-footer.php' ); ?>


Generated: Mon Apr 5 14:26:09 2010 Cross-referenced by PHPXref 0.7