3 * Multisite Users List Table class.
6 * @subpackage List_Table
10 class WP_MS_Users_List_Table extends WP_List_Table {
12 public function ajax_user_can() {
13 return current_user_can( 'manage_network_users' );
16 public function prepare_items() {
17 global $usersearch, $role, $wpdb, $mode;
19 $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_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')" );
44 * If the network is large and a search is not being performed,
45 * show only the latest users with no paging in order to avoid
46 * expensive count queries.
48 if ( !$usersearch && wp_is_large_network( 'users' ) ) {
49 if ( !isset($_REQUEST['orderby']) )
50 $_GET['orderby'] = $_REQUEST['orderby'] = 'id';
51 if ( !isset($_REQUEST['order']) )
52 $_GET['order'] = $_REQUEST['order'] = 'DESC';
53 $args['count_total'] = false;
56 if ( isset( $_REQUEST['orderby'] ) )
57 $args['orderby'] = $_REQUEST['orderby'];
59 if ( isset( $_REQUEST['order'] ) )
60 $args['order'] = $_REQUEST['order'];
62 $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
64 // Query the user IDs for this page
65 $wp_user_search = new WP_User_Query( $args );
67 $this->items = $wp_user_search->get_results();
69 $this->set_pagination_args( array(
70 'total_items' => $wp_user_search->get_total(),
71 'per_page' => $users_per_page,
75 protected function get_bulk_actions() {
77 if ( current_user_can( 'delete_users' ) )
78 $actions['delete'] = __( 'Delete' );
79 $actions['spam'] = _x( 'Mark as Spam', 'user' );
80 $actions['notspam'] = _x( 'Not Spam', 'user' );
85 public function no_items() {
86 _e( 'No users found.' );
89 protected function get_views() {
92 $total_users = get_user_count();
93 $super_admins = get_super_admins();
94 $total_admins = count( $super_admins );
96 $class = $role != 'super' ? ' class="current"' : '';
97 $role_links = array();
98 $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>';
99 $class = $role == 'super' ? ' class="current"' : '';
100 $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>';
106 * @global string $mode
107 * @param string $which
109 protected function pagination( $which ) {
112 parent::pagination ( $which );
114 if ( 'top' == $which )
115 $this->view_switcher( $mode );
118 public function get_columns() {
119 $users_columns = array(
120 'cb' => '<input type="checkbox" />',
121 'username' => __( 'Username' ),
122 'name' => __( 'Name' ),
123 'email' => __( 'E-mail' ),
124 'registered' => _x( 'Registered', 'user' ),
125 'blogs' => __( 'Sites' )
128 * Filter the columns displayed in the Network Admin Users list table.
132 * @param array $users_columns An array of user columns. Default 'cb', 'username',
133 * 'name', 'email', 'registered', 'blogs'.
135 $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
137 return $users_columns;
140 protected function get_sortable_columns() {
142 'username' => 'login',
145 'registered' => 'id',
149 public function display_rows() {
152 $super_admins = get_super_admins();
153 foreach ( $this->items as $user ) {
156 $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
158 foreach ( $status_list as $status => $col ) {
159 if ( $user->$status )
164 <tr class="<?php echo trim( $class ); ?>">
167 list( $columns, $hidden ) = $this->get_column_info();
169 foreach ( $columns as $column_name => $column_display_name ) :
170 $class = "class='$column_name column-$column_name'";
173 if ( in_array( $column_name, $hidden ) )
174 $style = ' style="display:none;"';
176 $attributes = "$class$style";
178 switch ( $column_name ) {
180 <th scope="row" class="check-column">
181 <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
182 <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
188 $avatar = get_avatar( $user->user_email, 32 );
189 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
191 echo "<td $attributes>"; ?>
192 <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
193 if ( in_array( $user->user_login, $super_admins ) )
194 echo ' - ' . __( 'Super Admin' );
199 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
201 if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
202 $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
206 * Filter the action links displayed under each user
207 * in the Network Admin Users list table.
211 * @param array $actions An array of action links to be displayed.
212 * Default 'Edit', 'Delete'.
213 * @param WP_User $user WP_User object.
215 $actions = apply_filters( 'ms_user_row_actions', $actions, $user );
216 echo $this->row_actions( $actions );
223 echo "<td $attributes>$user->first_name $user->last_name</td>";
227 echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
231 if ( 'list' == $mode )
232 $date = __( 'Y/m/d' );
234 $date = __( 'Y/m/d g:i:s a' );
236 echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
240 $blogs = get_blogs_of_user( $user->ID, true );
241 echo "<td $attributes>";
242 if ( is_array( $blogs ) ) {
243 foreach ( (array) $blogs as $key => $val ) {
244 if ( !can_edit_network( $val->site_id ) )
247 $path = ( $val->path == '/' ) ? '' : $val->path;
248 echo '<span class="site-' . $val->site_id . '" >';
249 echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . '</a>';
250 echo ' <small class="row-actions">';
252 $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
255 if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
256 $class .= 'site-spammed ';
257 if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 )
258 $class .= 'site-mature ';
259 if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 )
260 $class .= 'site-deleted ';
261 if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 )
262 $class .= 'site-archived ';
264 $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
267 * Filter the action links displayed next the sites a user belongs to
268 * in the Network Admin Users list table.
272 * @param array $actions An array of action links to be displayed.
273 * Default 'Edit', 'View'.
274 * @param int $userblog_id The site ID.
276 $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
279 $action_count = count( $actions );
280 foreach ( $actions as $action => $link ) {
282 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
283 echo "<span class='$action'>$link$sep</span>";
285 echo '</small></span><br/>';
294 echo "<td $attributes>";
295 /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
296 echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );