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