3 * Multisite Users List Table class.
6 * @subpackage List_Table
10 class WP_MS_Users_List_Table extends WP_List_Table {
12 function ajax_user_can() {
13 return current_user_can( 'manage_network_users' );
16 function prepare_items() {
17 global $usersearch, $role, $wpdb, $mode;
19 $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
21 $users_per_page = $this->get_items_per_page( 'users_network_per_page' );
23 $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
25 $paged = $this->get_pagenum();
28 'number' => $users_per_page,
29 'offset' => ( $paged-1 ) * $users_per_page,
30 'search' => $usersearch,
32 'fields' => 'all_with_meta'
35 if ( wp_is_large_network( 'users' ) )
36 $args['search'] = ltrim( $args['search'], '*' );
38 if ( $role == 'super' ) {
39 $logins = implode( "', '", get_super_admins() );
40 $args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
43 // If the network is large and a search is not being performed, show only the latest users with no paging in order
44 // to avoid expensive count queries.
45 if ( !$usersearch && wp_is_large_network( 'users' ) ) {
46 if ( !isset($_REQUEST['orderby']) )
47 $_GET['orderby'] = $_REQUEST['orderby'] = 'id';
48 if ( !isset($_REQUEST['order']) )
49 $_GET['order'] = $_REQUEST['order'] = 'DESC';
50 $args['count_total'] = false;
53 if ( isset( $_REQUEST['orderby'] ) )
54 $args['orderby'] = $_REQUEST['orderby'];
56 if ( isset( $_REQUEST['order'] ) )
57 $args['order'] = $_REQUEST['order'];
59 $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
61 // Query the user IDs for this page
62 $wp_user_search = new WP_User_Query( $args );
64 $this->items = $wp_user_search->get_results();
66 $this->set_pagination_args( array(
67 'total_items' => $wp_user_search->get_total(),
68 'per_page' => $users_per_page,
72 function get_bulk_actions() {
74 if ( current_user_can( 'delete_users' ) )
75 $actions['delete'] = __( 'Delete' );
76 $actions['spam'] = _x( 'Mark as Spam', 'user' );
77 $actions['notspam'] = _x( 'Not Spam', 'user' );
83 _e( 'No users found.' );
86 function get_views() {
87 global $wp_roles, $role;
89 $total_users = get_user_count();
90 $super_admins = get_super_admins();
91 $total_admins = count( $super_admins );
93 $current_role = false;
94 $class = $role != 'super' ? ' class="current"' : '';
95 $role_links = array();
96 $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>';
97 $class = $role == 'super' ? ' class="current"' : '';
98 $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>';
103 function pagination( $which ) {
106 parent::pagination ( $which );
108 if ( 'top' == $which )
109 $this->view_switcher( $mode );
112 function get_columns() {
113 $users_columns = array(
114 'cb' => '<input type="checkbox" />',
115 'username' => __( 'Username' ),
116 'name' => __( 'Name' ),
117 'email' => __( 'E-mail' ),
118 'registered' => _x( 'Registered', 'user' ),
119 'blogs' => __( 'Sites' )
121 $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
123 return $users_columns;
126 function get_sortable_columns() {
128 'username' => 'login',
131 'registered' => 'id',
135 function display_rows() {
136 global $current_site, $mode;
139 $super_admins = get_super_admins();
140 foreach ( $this->items as $user ) {
141 $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
143 $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
145 foreach ( $status_list as $status => $col ) {
146 if ( $user->$status )
151 <tr class="<?php echo $alt; ?>">
154 list( $columns, $hidden ) = $this->get_column_info();
156 foreach ( $columns as $column_name => $column_display_name ) :
157 $class = "class='$column_name column-$column_name'";
160 if ( in_array( $column_name, $hidden ) )
161 $style = ' style="display:none;"';
163 $attributes = "$class$style";
166 switch ( $column_name ) {
168 <th scope="row" class="check-column">
169 <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
175 $avatar = get_avatar( $user->user_email, 32 );
176 if ( get_current_user_id() == $user->ID ) {
177 $edit_link = esc_url( network_admin_url( 'profile.php' ) );
179 $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 ) ) );
182 echo "<td $attributes>"; ?>
183 <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo stripslashes( $user->user_login ); ?></a><?php
184 if ( in_array( $user->user_login, $super_admins ) )
185 echo ' - ' . __( 'Super Admin' );
190 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
192 if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
193 $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
196 $actions = apply_filters( 'ms_user_row_actions', $actions, $user );
197 echo $this->row_actions( $actions );
204 echo "<td $attributes>$user->first_name $user->last_name</td>";
208 echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
212 if ( 'list' == $mode )
215 $date = 'Y/m/d \<\b\r \/\> g:i:s a';
217 echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
221 $blogs = get_blogs_of_user( $user->ID, true );
222 echo "<td $attributes>";
223 if ( is_array( $blogs ) ) {
224 foreach ( (array) $blogs as $key => $val ) {
225 if ( !can_edit_network( $val->site_id ) )
228 $path = ( $val->path == '/' ) ? '' : $val->path;
229 echo '<span class="site-' . $val->site_id . '" >';
230 echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>';
231 echo ' <small class="row-actions">';
233 $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
236 if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
237 $class .= 'site-spammed ';
238 if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 )
239 $class .= 'site-mature ';
240 if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 )
241 $class .= 'site-deleted ';
242 if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 )
243 $class .= 'site-archived ';
245 $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
247 $actions = apply_filters('ms_user_list_site_actions', $actions, $val->userblog_id);
250 $action_count = count( $actions );
251 foreach ( $actions as $action => $link ) {
253 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
254 echo "<span class='$action'>$link$sep</span>";
256 echo '</small></span><br/>';
265 echo "<td $attributes>";
266 echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );