~canonical-sysadmins/wordpress/4.8.3

« back to all changes in this revision

Viewing changes to wp-admin/includes/class-wp-ms-users-list-table.php

  • Committer: Ryan Finnie
  • Date: 2015-08-31 16:09:47 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: ryan.finnie@canonical.com-20150831160947-1h6rfxby9z1ec62u
Merge WP4.3 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 * @access private
9
9
 */
10
10
class WP_MS_Users_List_Table extends WP_List_Table {
11
 
 
 
11
        /**
 
12
         *
 
13
         * @return bool
 
14
         */
12
15
        public function ajax_user_can() {
13
16
                return current_user_can( 'manage_network_users' );
14
17
        }
15
18
 
 
19
        /**
 
20
         *
 
21
         * @global string $usersearch
 
22
         * @global string $role
 
23
         * @global wpdb   $wpdb
 
24
         * @global string $mode
 
25
         */
16
26
        public function prepare_items() {
17
27
                global $usersearch, $role, $wpdb, $mode;
18
28
 
72
82
                ) );
73
83
        }
74
84
 
 
85
        /**
 
86
         *
 
87
         * @return array
 
88
         */
75
89
        protected function get_bulk_actions() {
76
90
                $actions = array();
77
91
                if ( current_user_can( 'delete_users' ) )
82
96
                return $actions;
83
97
        }
84
98
 
 
99
        /**
 
100
         * @access public
 
101
         */
85
102
        public function no_items() {
86
103
                _e( 'No users found.' );
87
104
        }
88
105
 
 
106
        /**
 
107
         *
 
108
         * @global string $role
 
109
         * @return array
 
110
         */
89
111
        protected function get_views() {
90
112
                global $role;
91
113
 
115
137
                        $this->view_switcher( $mode );
116
138
        }
117
139
 
 
140
        /**
 
141
         *
 
142
         * @return array
 
143
         */
118
144
        public function get_columns() {
119
145
                $users_columns = array(
120
146
                        'cb'         => '<input type="checkbox" />',
132
158
                 * @param array $users_columns An array of user columns. Default 'cb', 'username',
133
159
                 *                             'name', 'email', 'registered', 'blogs'.
134
160
                 */
135
 
                $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
136
 
 
137
 
                return $users_columns;
 
161
                return apply_filters( 'wpmu_users_columns', $users_columns );
138
162
        }
139
163
 
 
164
        /**
 
165
         *
 
166
         * @return array
 
167
         */
140
168
        protected function get_sortable_columns() {
141
169
                return array(
142
170
                        'username'   => 'login',
146
174
                );
147
175
        }
148
176
 
 
177
        /**
 
178
         * Handles the checkbox column output.
 
179
         *
 
180
         * @since 4.3.0
 
181
         * @access public
 
182
         *
 
183
         * @param WP_User $user The current WP_User object.
 
184
         */
 
185
        public function column_cb( $user ) {
 
186
                ?>
 
187
                <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
 
188
                <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
 
189
                <?php
 
190
        }
 
191
 
 
192
        /**
 
193
         * Handles the username column output.
 
194
         *
 
195
         * @since 4.3.0
 
196
         * @access public
 
197
         *
 
198
         * @param WP_User $user The current WP_User object.
 
199
         */
 
200
        public function column_username( $user ) {
 
201
                $super_admins = get_super_admins();
 
202
                $avatar = get_avatar( $user->user_email, 32 );
 
203
                $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
 
204
 
 
205
                echo $avatar;
 
206
 
 
207
                ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
 
208
                if ( in_array( $user->user_login, $super_admins ) ) {
 
209
                        echo ' - ' . __( 'Super Admin' );
 
210
                }
 
211
                ?></strong>
 
212
        <?php
 
213
        }
 
214
 
 
215
        /**
 
216
         * Handles the name column output.
 
217
         *
 
218
         * @since 4.3.0
 
219
         * @access public
 
220
         *
 
221
         * @param WP_User $user The current WP_User object.
 
222
         */
 
223
        public function column_name( $user ) {
 
224
                echo "$user->first_name $user->last_name";
 
225
        }
 
226
 
 
227
        /**
 
228
         * Handles the email column output.
 
229
         *
 
230
         * @since 4.3.0
 
231
         * @access public
 
232
         *
 
233
         * @param WP_User $user The current WP_User object.
 
234
         */
 
235
        public function column_email( $user ) {
 
236
                echo "<a href='mailto:$user->user_email'>$user->user_email</a>";
 
237
        }
 
238
 
 
239
        /**
 
240
         * Handles the registered date column output.
 
241
         *
 
242
         * @since 4.3.0
 
243
         * @access public
 
244
         *
 
245
         * @global string $mode
 
246
         *
 
247
         * @param WP_User $user The current WP_User object.
 
248
         */
 
249
        public function column_registered( $user ) {
 
250
                global $mode;
 
251
                if ( 'list' == $mode ) {
 
252
                        $date = __( 'Y/m/d' );
 
253
                } else {
 
254
                        $date = __( 'Y/m/d g:i:s a' );
 
255
                }
 
256
                echo mysql2date( $date, $user->user_registered );
 
257
        }
 
258
 
 
259
        /**
 
260
         * @since 4.3.0
 
261
         * @access protected
 
262
         *
 
263
         * @param WP_User $user
 
264
         * @param string  $classes
 
265
         * @param string  $data
 
266
         * @param string  $primary
 
267
         */
 
268
        protected function _column_blogs( $user, $classes, $data, $primary ) {
 
269
                echo '<td class="', $classes, ' has-row-actions" ', $data, '>';
 
270
                echo $this->column_blogs( $user );
 
271
                echo $this->handle_row_actions( $user, 'blogs', $primary );
 
272
                echo '</td>';
 
273
        }
 
274
 
 
275
        /**
 
276
         * Handles the blogs/sites column output.
 
277
         *
 
278
         * @since 4.3.0
 
279
         * @access public
 
280
         *
 
281
         * @param WP_User $user The current WP_User object.
 
282
         */
 
283
        public function column_blogs( $user ) {
 
284
                $blogs = get_blogs_of_user( $user->ID, true );
 
285
                if ( ! is_array( $blogs ) ) {
 
286
                        return;
 
287
                }
 
288
 
 
289
                foreach ( $blogs as $val ) {
 
290
                        if ( ! can_edit_network( $val->site_id ) ) {
 
291
                                continue;
 
292
                        }
 
293
 
 
294
                        $path   = ( $val->path == '/' ) ? '' : $val->path;
 
295
                        echo '<span class="site-' . $val->site_id . '" >';
 
296
                        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>';
 
297
                        echo ' <small class="row-actions">';
 
298
                        $actions = array();
 
299
                        $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
 
300
 
 
301
                        $class = '';
 
302
                        if ( $val->spam == 1 ) {
 
303
                                $class .= 'site-spammed ';
 
304
                        }
 
305
                        if ( $val->mature == 1 ) {
 
306
                                $class .= 'site-mature ';
 
307
                        }
 
308
                        if ( $val->deleted == 1 ) {
 
309
                                $class .= 'site-deleted ';
 
310
                        }
 
311
                        if ( $val->archived == 1 ) {
 
312
                                $class .= 'site-archived ';
 
313
                        }
 
314
 
 
315
                        $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
 
316
 
 
317
                        /**
 
318
                         * Filter the action links displayed next the sites a user belongs to
 
319
                         * in the Network Admin Users list table.
 
320
                         *
 
321
                         * @since 3.1.0
 
322
                         *
 
323
                         * @param array $actions     An array of action links to be displayed.
 
324
                         *                           Default 'Edit', 'View'.
 
325
                         * @param int   $userblog_id The site ID.
 
326
                         */
 
327
                        $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
 
328
 
 
329
                        $i=0;
 
330
                        $action_count = count( $actions );
 
331
                        foreach ( $actions as $action => $link ) {
 
332
                                ++$i;
 
333
                                $sep = ( $i == $action_count ) ? '' : ' | ';
 
334
                                echo "<span class='$action'>$link$sep</span>";
 
335
                        }
 
336
                        echo '</small></span><br/>';
 
337
                }
 
338
        }
 
339
 
 
340
        /**
 
341
         * Handles the default column output.
 
342
         *
 
343
         * @since 4.3.0
 
344
         * @access public
 
345
         *
 
346
         * @param WP_User $user       The current WP_User object.
 
347
         * @param string $column_name The current column name.
 
348
         */
 
349
        public function column_default( $user, $column_name ) {
 
350
                /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
 
351
                echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
 
352
        }
 
353
 
149
354
        public function display_rows() {
150
 
                global $mode;
151
 
 
152
 
                $super_admins = get_super_admins();
153
355
                foreach ( $this->items as $user ) {
154
356
                        $class = '';
155
357
 
156
358
                        $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
157
359
 
158
360
                        foreach ( $status_list as $status => $col ) {
159
 
                                if ( $user->$status )
 
361
                                if ( $user->$status ) {
160
362
                                        $class .= " $col";
 
363
                                }
161
364
                        }
162
365
 
163
366
                        ?>
164
367
                        <tr class="<?php echo trim( $class ); ?>">
165
 
                        <?php
166
 
 
167
 
                        list( $columns, $hidden ) = $this->get_column_info();
168
 
 
169
 
                        foreach ( $columns as $column_name => $column_display_name ) :
170
 
                                $class = "class='$column_name column-$column_name'";
171
 
 
172
 
                                $style = '';
173
 
                                if ( in_array( $column_name, $hidden ) )
174
 
                                        $style = ' style="display:none;"';
175
 
 
176
 
                                $attributes = "$class$style";
177
 
 
178
 
                                switch ( $column_name ) {
179
 
                                        case 'cb': ?>
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 ) ?>" />
183
 
                                                </th>
184
 
                                        <?php
185
 
                                        break;
186
 
 
187
 
                                        case 'username':
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 ) ) );
190
 
 
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' );
195
 
                                                        ?></strong>
196
 
                                                        <br/>
197
 
                                                        <?php
198
 
                                                                $actions = array();
199
 
                                                                $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
200
 
 
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' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
203
 
                                                                }
204
 
 
205
 
                                                                /**
206
 
                                                                 * Filter the action links displayed under each user
207
 
                                                                 * in the Network Admin Users list table.
208
 
                                                                 *
209
 
                                                                 * @since 3.2.0
210
 
                                                                 *
211
 
                                                                 * @param array   $actions An array of action links to be displayed.
212
 
                                                                 *                         Default 'Edit', 'Delete'.
213
 
                                                                 * @param WP_User $user    WP_User object.
214
 
                                                                 */
215
 
                                                                $actions = apply_filters( 'ms_user_row_actions', $actions, $user );
216
 
                                                                echo $this->row_actions( $actions );
217
 
                                                        ?>
218
 
                                                </td>
219
 
                                        <?php
220
 
                                        break;
221
 
 
222
 
                                        case 'name':
223
 
                                                echo "<td $attributes>$user->first_name $user->last_name</td>";
224
 
                                        break;
225
 
 
226
 
                                        case 'email':
227
 
                                                echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
228
 
                                        break;
229
 
 
230
 
                                        case 'registered':
231
 
                                                if ( 'list' == $mode )
232
 
                                                        $date = __( 'Y/m/d' );
233
 
                                                else
234
 
                                                        $date = __( 'Y/m/d g:i:s a' );
235
 
 
236
 
                                                echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
237
 
                                        break;
238
 
 
239
 
                                        case 'blogs':
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 ) )
245
 
                                                                                continue;
246
 
 
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">';
251
 
                                                                        $actions = array();
252
 
                                                                        $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
253
 
 
254
 
                                                                        $class = '';
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 ';
263
 
 
264
 
                                                                        $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
265
 
 
266
 
                                                                        /**
267
 
                                                                         * Filter the action links displayed next the sites a user belongs to
268
 
                                                                         * in the Network Admin Users list table.
269
 
                                                                         *
270
 
                                                                         * @since 3.1.0
271
 
                                                                         *
272
 
                                                                         * @param array $actions     An array of action links to be displayed.
273
 
                                                                         *                           Default 'Edit', 'View'.
274
 
                                                                         * @param int   $userblog_id The site ID.
275
 
                                                                         */
276
 
                                                                        $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
277
 
 
278
 
                                                                        $i=0;
279
 
                                                                        $action_count = count( $actions );
280
 
                                                                        foreach ( $actions as $action => $link ) {
281
 
                                                                                ++$i;
282
 
                                                                                ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
283
 
                                                                                echo "<span class='$action'>$link$sep</span>";
284
 
                                                                        }
285
 
                                                                        echo '</small></span><br/>';
286
 
                                                                }
287
 
                                                        }
288
 
                                                        ?>
289
 
                                                </td>
290
 
                                        <?php
291
 
                                        break;
292
 
 
293
 
                                        default:
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 );
297
 
                                                echo "</td>";
298
 
                                        break;
299
 
                                }
300
 
                        endforeach
301
 
                        ?>
 
368
                                <?php $this->single_row_columns( $user ); ?>
302
369
                        </tr>
303
370
                        <?php
304
371
                }
305
372
        }
 
373
 
 
374
        /**
 
375
         * Gets the name of the default primary column.
 
376
         *
 
377
         * @since 4.3.0
 
378
         * @access protected
 
379
         *
 
380
         * @return string Name of the default primary column, in this case, 'username'.
 
381
         */
 
382
        protected function get_default_primary_column_name() {
 
383
                return 'username';
 
384
        }
 
385
 
 
386
        /**
 
387
         * Generates and displays row action links.
 
388
         *
 
389
         * @since 4.3.0
 
390
         * @access protected
 
391
         *
 
392
         * @param object $user        User being acted upon.
 
393
         * @param string $column_name Current column name.
 
394
         * @param string $primary     Primary column name.
 
395
         * @return string Row actions output for users in Multisite.
 
396
         */
 
397
        protected function handle_row_actions( $user, $column_name, $primary ) {
 
398
                if ( $primary !== $column_name ) {
 
399
                        return '';
 
400
                }
 
401
 
 
402
                $super_admins = get_super_admins();
 
403
                $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
 
404
 
 
405
                $actions = array();
 
406
                $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
 
407
 
 
408
                if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
 
409
                        $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>';
 
410
                }
 
411
 
 
412
                /**
 
413
                 * Filter the action links displayed under each user in the Network Admin Users list table.
 
414
                 *
 
415
                 * @since 3.2.0
 
416
                 *
 
417
                 * @param array   $actions An array of action links to be displayed.
 
418
                 *                         Default 'Edit', 'Delete'.
 
419
                 * @param WP_User $user    WP_User object.
 
420
                 */
 
421
                $actions = apply_filters( 'ms_user_row_actions', $actions, $user );
 
422
                return $this->row_actions( $actions );
 
423
        }
306
424
}