]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-ms-users-list-table.php
WordPress 3.8.1
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-ms-users-list-table.php
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                 if ( wp_is_large_network( 'users' ) )
36                         $args['search'] = ltrim( $args['search'], '*' );
37
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')" );
41                 }
42
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;
51                 }
52
53                 if ( isset( $_REQUEST['orderby'] ) )
54                         $args['orderby'] = $_REQUEST['orderby'];
55
56                 if ( isset( $_REQUEST['order'] ) )
57                         $args['order'] = $_REQUEST['order'];
58
59                 $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
60
61                 // Query the user IDs for this page
62                 $wp_user_search = new WP_User_Query( $args );
63
64                 $this->items = $wp_user_search->get_results();
65
66                 $this->set_pagination_args( array(
67                         'total_items' => $wp_user_search->get_total(),
68                         'per_page' => $users_per_page,
69                 ) );
70         }
71
72         function get_bulk_actions() {
73                 $actions = array();
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' );
78
79                 return $actions;
80         }
81
82         function no_items() {
83                 _e( 'No users found.' );
84         }
85
86         function get_views() {
87                 global $wp_roles, $role;
88
89                 $total_users = get_user_count();
90                 $super_admins = get_super_admins();
91                 $total_admins = count( $super_admins );
92
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>';
99
100                 return $role_links;
101         }
102
103         function pagination( $which ) {
104                 global $mode;
105
106                 parent::pagination ( $which );
107
108                 if ( 'top' == $which )
109                         $this->view_switcher( $mode );
110         }
111
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' )
120                 );
121                 /**
122                  * Filter the columns displayed in the Network Admin Users list table.
123                  *
124                  * @since MU
125                  *
126                  * @param array $users_columns An array of user columns. Default 'cb', 'username',
127                  *                             'name', 'email', 'registered', 'blogs'.
128                  */
129                 $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
130
131                 return $users_columns;
132         }
133
134         function get_sortable_columns() {
135                 return array(
136                         'username'   => 'login',
137                         'name'       => 'name',
138                         'email'      => 'email',
139                         'registered' => 'id',
140                 );
141         }
142
143         function display_rows() {
144                 global $mode;
145
146                 $alt = '';
147                 $super_admins = get_super_admins();
148                 foreach ( $this->items as $user ) {
149                         $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
150
151                         $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
152
153                         foreach ( $status_list as $status => $col ) {
154                                 if ( $user->$status )
155                                         $alt .= " $col";
156                         }
157
158                         ?>
159                         <tr class="<?php echo $alt; ?>">
160                         <?php
161
162                         list( $columns, $hidden ) = $this->get_column_info();
163
164                         foreach ( $columns as $column_name => $column_display_name ) :
165                                 $class = "class='$column_name column-$column_name'";
166
167                                 $style = '';
168                                 if ( in_array( $column_name, $hidden ) )
169                                         $style = ' style="display:none;"';
170
171                                 $attributes = "$class$style";
172
173                                 switch ( $column_name ) {
174                                         case 'cb': ?>
175                                                 <th scope="row" class="check-column">
176                                                         <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
177                                                         <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
178                                                 </th>
179                                         <?php
180                                         break;
181
182                                         case 'username':
183                                                 $avatar = get_avatar( $user->user_email, 32 );
184                                                 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
185
186                                                 echo "<td $attributes>"; ?>
187                                                         <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
188                                                         if ( in_array( $user->user_login, $super_admins ) )
189                                                                 echo ' - ' . __( 'Super Admin' );
190                                                         ?></strong>
191                                                         <br/>
192                                                         <?php
193                                                                 $actions = array();
194                                                                 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
195
196                                                                 if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
197                                                                         $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' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
198                                                                 }
199
200                                                                 /**
201                                                                  * Filter the action links displayed under each user
202                                                                  * in the Network Admin Users list table.
203                                                                  *
204                                                                  * @since 3.2.0
205                                                                  *
206                                                                  * @param array   $actions An array of action links to be displayed.
207                                                                  *                         Default 'Edit', 'Delete'.
208                                                                  * @param WP_User $user    WP_User object.
209                                                                  */
210                                                                 $actions = apply_filters( 'ms_user_row_actions', $actions, $user );
211                                                                 echo $this->row_actions( $actions );
212                                                         ?>
213                                                 </td>
214                                         <?php
215                                         break;
216
217                                         case 'name':
218                                                 echo "<td $attributes>$user->first_name $user->last_name</td>";
219                                         break;
220
221                                         case 'email':
222                                                 echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
223                                         break;
224
225                                         case 'registered':
226                                                 if ( 'list' == $mode )
227                                                         $date = 'Y/m/d';
228                                                 else
229                                                         $date = 'Y/m/d \<\b\r \/\> g:i:s a';
230
231                                                 echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
232                                         break;
233
234                                         case 'blogs':
235                                                 $blogs = get_blogs_of_user( $user->ID, true );
236                                                 echo "<td $attributes>";
237                                                         if ( is_array( $blogs ) ) {
238                                                                 foreach ( (array) $blogs as $key => $val ) {
239                                                                         if ( !can_edit_network( $val->site_id ) )
240                                                                                 continue;
241
242                                                                         $path   = ( $val->path == '/' ) ? '' : $val->path;
243                                                                         echo '<span class="site-' . $val->site_id . '" >';
244                                                                         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>';
245                                                                         echo ' <small class="row-actions">';
246                                                                         $actions = array();
247                                                                         $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
248
249                                                                         $class = '';
250                                                                         if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
251                                                                                 $class .= 'site-spammed ';
252                                                                         if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 )
253                                                                                 $class .= 'site-mature ';
254                                                                         if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 )
255                                                                                 $class .= 'site-deleted ';
256                                                                         if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 )
257                                                                                 $class .= 'site-archived ';
258
259                                                                         $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
260
261                                                                         /**
262                                                                          * Filter the action links displayed next the sites a user belongs to
263                                                                          * in the Network Admin Users list table.
264                                                                          *
265                                                                          * @since 3.1.0
266                                                                          *
267                                                                          * @param array $actions     An array of action links to be displayed.
268                                                                          *                           Default 'Edit', 'View'.
269                                                                          * @param int   $userblog_id The site ID.
270                                                                          */
271                                                                         $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
272
273                                                                         $i=0;
274                                                                         $action_count = count( $actions );
275                                                                         foreach ( $actions as $action => $link ) {
276                                                                                 ++$i;
277                                                                                 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
278                                                                                 echo "<span class='$action'>$link$sep</span>";
279                                                                         }
280                                                                         echo '</small></span><br/>';
281                                                                 }
282                                                         }
283                                                         ?>
284                                                 </td>
285                                         <?php
286                                         break;
287
288                                         default:
289                                                 echo "<td $attributes>";
290                                                 /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
291                                                 echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
292                                                 echo "</td>";
293                                         break;
294                                 }
295                         endforeach
296                         ?>
297                         </tr>
298                         <?php
299                 }
300         }
301 }