3 * User administration panel
6 * @subpackage Administration
10 /** WordPress Administration Bootstrap */
11 require_once( dirname( __FILE__ ) . '/admin.php' );
13 if ( ! current_user_can( 'list_users' ) ) {
15 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
16 '<p>' . __( 'You are not allowed to browse users.' ) . '</p>',
21 $wp_list_table = _get_list_table('WP_Users_List_Table');
22 $pagenum = $wp_list_table->get_pagenum();
24 $parent_file = 'users.php';
26 add_screen_option( 'per_page' );
28 // contextual help - choose Help on the top right of admin panel to preview this.
29 get_current_screen()->add_help_tab( array(
31 'title' => __('Overview'),
32 'content' => '<p>' . __('This screen lists all the existing users for your site. Each user has one of five defined roles as set by the site admin: Site Administrator, Editor, Author, Contributor, or Subscriber. Users with roles other than Administrator will see fewer options in the dashboard navigation when they are logged in, based on their role.') . '</p>' .
33 '<p>' . __('To add a new user for your site, click the Add New button at the top of the screen or Add New in the Users menu section.') . '</p>'
36 get_current_screen()->add_help_tab( array(
37 'id' => 'screen-display',
38 'title' => __('Screen Display'),
39 'content' => '<p>' . __('You can customize the display of this screen in a number of ways:') . '</p>' .
41 '<li>' . __('You can hide/display columns based on your needs and decide how many users to list per screen using the Screen Options tab.') . '</li>' .
42 '<li>' . __('You can filter the list of users by User Role using the text links in the upper left to show All, Administrator, Editor, Author, Contributor, or Subscriber. The default view is to show all users. Unused User Roles are not listed.') . '</li>' .
43 '<li>' . __('You can view all posts made by a user by clicking on the number under the Posts column.') . '</li>' .
47 $help = '<p>' . __('Hovering over a row in the users list will display action links that allow you to manage users. You can perform the following actions:') . '</p>' .
49 '<li>' . __('Edit takes you to the editable profile screen for that user. You can also reach that screen by clicking on the username.') . '</li>';
52 $help .= '<li>' . __( 'Remove allows you to remove a user from your site. It does not delete their content. You can also remove multiple users at once by using Bulk Actions.' ) . '</li>';
54 $help .= '<li>' . __( 'Delete brings you to the Delete Users screen for confirmation, where you can permanently remove a user from your site and delete their content. You can also delete multiple users at once by using Bulk Actions.' ) . '</li>';
58 get_current_screen()->add_help_tab( array(
60 'title' => __('Actions'),
65 get_current_screen()->set_help_sidebar(
66 '<p><strong>' . __('For more information:') . '</strong></p>' .
67 '<p>' . __('<a href="https://codex.wordpress.org/Users_Screen" target="_blank">Documentation on Managing Users</a>') . '</p>' .
68 '<p>' . __('<a href="https://codex.wordpress.org/Roles_and_Capabilities" target="_blank">Descriptions of Roles and Capabilities</a>') . '</p>' .
69 '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
72 get_current_screen()->set_screen_reader_content( array(
73 'heading_views' => __( 'Filter users list' ),
74 'heading_pagination' => __( 'Users list navigation' ),
75 'heading_list' => __( 'Users list' ),
78 if ( empty($_REQUEST) ) {
79 $referer = '<input type="hidden" name="wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
80 } elseif ( isset($_REQUEST['wp_http_referer']) ) {
81 $redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), wp_unslash( $_REQUEST['wp_http_referer'] ) );
82 $referer = '<input type="hidden" name="wp_http_referer" value="' . esc_attr($redirect) . '" />';
84 $redirect = 'users.php';
90 switch ( $wp_list_table->current_action() ) {
92 /* Bulk Dropdown menu Role changes */
94 check_admin_referer('bulk-users');
96 if ( ! current_user_can( 'promote_users' ) )
97 wp_die( __( 'You can’t edit that user.' ) );
99 if ( empty($_REQUEST['users']) ) {
100 wp_redirect($redirect);
104 $editable_roles = get_editable_roles();
106 if ( ! empty( $_REQUEST['new_role2'] ) ) {
107 $role = $_REQUEST['new_role2'];
108 } elseif ( ! empty( $_REQUEST['new_role'] ) ) {
109 $role = $_REQUEST['new_role'];
112 if ( ! $role || empty( $editable_roles[ $role ] ) ) {
113 wp_die( __( 'You can’t give users that role.' ) );
116 $userids = $_REQUEST['users'];
118 foreach ( $userids as $id ) {
121 if ( ! current_user_can('promote_user', $id) )
122 wp_die(__('You can’t edit that user.'));
123 // The new role of the current user must also have the promote_users cap or be a multisite super admin
124 if ( $id == $current_user->ID && ! $wp_roles->role_objects[ $role ]->has_cap('promote_users')
125 && ! ( is_multisite() && is_super_admin() ) ) {
126 $update = 'err_admin_role';
130 // If the user doesn't already belong to the blog, bail.
131 if ( is_multisite() && !is_user_member_of_blog( $id ) ) {
133 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
134 '<p>' . __( 'One of the selected users is not a member of this site.' ) . '</p>',
139 $user = get_userdata( $id );
140 $user->set_role( $role );
143 wp_redirect(add_query_arg('update', $update, $redirect));
147 if ( is_multisite() )
148 wp_die( __('User deletion is not allowed from this screen.') );
150 check_admin_referer('delete-users');
152 if ( empty($_REQUEST['users']) ) {
153 wp_redirect($redirect);
157 $userids = array_map( 'intval', (array) $_REQUEST['users'] );
159 if ( empty( $_REQUEST['delete_option'] ) ) {
160 $url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $userids ) . '&error=true' );
161 $url = str_replace( '&', '&', wp_nonce_url( $url, 'bulk-users' ) );
166 if ( ! current_user_can( 'delete_users' ) )
167 wp_die(__('You can’t delete users.'));
172 foreach ( $userids as $id ) {
173 if ( ! current_user_can( 'delete_user', $id ) )
174 wp_die(__( 'You can’t delete that user.' ) );
176 if ( $id == $current_user->ID ) {
177 $update = 'err_admin_del';
180 switch ( $_REQUEST['delete_option'] ) {
182 wp_delete_user( $id );
185 wp_delete_user( $id, $_REQUEST['reassign_user'] );
191 $redirect = add_query_arg( array('delete_count' => $delete_count, 'update' => $update), $redirect);
192 wp_redirect($redirect);
196 if ( is_multisite() )
197 wp_die( __('User deletion is not allowed from this screen.') );
199 check_admin_referer('bulk-users');
201 if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) {
202 wp_redirect($redirect);
206 if ( ! current_user_can( 'delete_users' ) )
207 $errors = new WP_Error( 'edit_users', __( 'You can’t delete users.' ) );
209 if ( empty($_REQUEST['users']) )
210 $userids = array( intval( $_REQUEST['user'] ) );
212 $userids = array_map( 'intval', (array) $_REQUEST['users'] );
214 $users_posts = new WP_Query( array(
215 'post_type' => 'any',
216 'author' => implode( ',', $userids ),
217 'posts_per_page' => 1
220 if ( $users_posts->have_posts() ) {
221 add_action( 'admin_head', 'delete_users_add_js' );
224 include( ABSPATH . 'wp-admin/admin-header.php' );
226 <form method="post" name="updateusers" id="updateusers">
227 <?php wp_nonce_field('delete-users') ?>
228 <?php echo $referer; ?>
231 <h1><?php _e( 'Delete Users' ); ?></h1>
232 <?php if ( isset( $_REQUEST['error'] ) ) : ?>
234 <p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'Please select an option.' ); ?></p>
238 <?php if ( 1 == count( $userids ) ) : ?>
239 <p><?php _e( 'You have specified this user for deletion:' ); ?></p>
241 <p><?php _e( 'You have specified these users for deletion:' ); ?></p>
247 foreach ( $userids as $id ) {
248 $user = get_userdata( $id );
249 if ( $id == $current_user->ID ) {
250 echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
252 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n";
258 <?php if ( $go_delete ) :
260 if ( ! $users_posts->have_posts() ) : ?>
261 <input type="hidden" name="delete_option" value="delete" />
263 <?php if ( 1 == $go_delete ) : ?>
264 <fieldset><p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p>
266 <fieldset><p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p>
268 <ul style="list-style:none;">
269 <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" />
270 <?php _e('Delete all content.'); ?></label></li>
271 <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
272 <?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
273 wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
277 * Fires at the end of the delete users form prior to the confirm button.
281 * @param WP_User $current_user WP_User object for the user being deleted.
283 do_action( 'delete_user_form', $current_user );
285 <input type="hidden" name="action" value="dodelete" />
286 <?php submit_button( __('Confirm Deletion'), 'primary' ); ?>
288 <p><?php _e('There are no valid users selected for deletion.'); ?></p>
297 check_admin_referer('remove-users');
299 if ( ! is_multisite() )
300 wp_die( __( 'You can’t remove users.' ) );
302 if ( empty($_REQUEST['users']) ) {
303 wp_redirect($redirect);
307 if ( ! current_user_can( 'remove_users' ) )
308 wp_die( __( 'You can’t remove users.' ) );
310 $userids = $_REQUEST['users'];
313 foreach ( $userids as $id ) {
315 if ( $id == $current_user->ID && !is_super_admin() ) {
316 $update = 'err_admin_remove';
319 if ( !current_user_can('remove_user', $id) ) {
320 $update = 'err_admin_remove';
323 remove_user_from_blog($id, $blog_id);
326 $redirect = add_query_arg( array('update' => $update), $redirect);
327 wp_redirect($redirect);
332 check_admin_referer('bulk-users');
334 if ( ! is_multisite() )
335 wp_die( __( 'You can’t remove users.' ) );
337 if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) {
338 wp_redirect($redirect);
342 if ( !current_user_can('remove_users') )
343 $error = new WP_Error('edit_users', __('You can’t remove users.'));
345 if ( empty($_REQUEST['users']) )
346 $userids = array(intval($_REQUEST['user']));
348 $userids = $_REQUEST['users'];
350 include( ABSPATH . 'wp-admin/admin-header.php' );
352 <form method="post" name="updateusers" id="updateusers">
353 <?php wp_nonce_field('remove-users') ?>
354 <?php echo $referer; ?>
357 <h1><?php _e( 'Remove Users from Site' ); ?></h1>
359 <?php if ( 1 == count( $userids ) ) : ?>
360 <p><?php _e( 'You have specified this user for removal:' ); ?></p>
362 <p><?php _e( 'You have specified these users for removal:' ); ?></p>
368 foreach ( $userids as $id ) {
370 $user = get_userdata( $id );
371 if ( $id == $current_user->ID && !is_super_admin() ) {
372 echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
373 } elseif ( !current_user_can('remove_user', $id) ) {
374 echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>You don\'t have permission to remove this user.</strong>'), $id, $user->user_login) . "</li>\n";
376 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n";
382 <?php if ( $go_remove ) : ?>
383 <input type="hidden" name="action" value="doremove" />
384 <?php submit_button( __('Confirm Removal'), 'primary' ); ?>
386 <p><?php _e('There are no valid users selected for removal.'); ?></p>
396 if ( !empty($_GET['_wp_http_referer']) ) {
397 wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce'), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
401 $wp_list_table->prepare_items();
402 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
403 if ( $pagenum > $total_pages && $total_pages > 0 ) {
404 wp_redirect( add_query_arg( 'paged', $total_pages ) );
408 include( ABSPATH . 'wp-admin/admin-header.php' );
411 if ( isset($_GET['update']) ) :
412 switch($_GET['update']) {
415 $delete_count = isset($_GET['delete_count']) ? (int) $_GET['delete_count'] : 0;
416 if ( 1 == $delete_count ) {
417 $message = __( 'User deleted.' );
419 $message = _n( '%s user deleted.', '%s users deleted.', $delete_count );
421 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $delete_count ) ) . '</p></div>';
424 if ( isset( $_GET['id'] ) && ( $user_id = $_GET['id'] ) && current_user_can( 'edit_user', $user_id ) ) {
425 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( __( 'New user created. <a href="%s">Edit user</a>' ),
426 esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
427 self_admin_url( 'user-edit.php?user_id=' . $user_id ) ) ) ) . '</p></div>';
429 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'New user created.' ) . '</p></div>';
433 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __('Changed roles.') . '</p></div>';
435 case 'err_admin_role':
436 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __('The current user’s role must have user editing capabilities.') . '</p></div>';
437 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __('Other user roles have been changed.') . '</p></div>';
439 case 'err_admin_del':
440 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __('You can’t delete the current user.') . '</p></div>';
441 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __('Other users have been deleted.') . '</p></div>';
444 $messages[] = '<div id="message" class="updated notice is-dismissible fade"><p>' . __('User removed from this site.') . '</p></div>';
446 case 'err_admin_remove':
447 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __("You can't remove the current user.") . '</p></div>';
448 $messages[] = '<div id="message" class="updated notice is-dismissible fade"><p>' . __('Other users have been removed.') . '</p></div>';
453 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?>
457 foreach ( $errors->get_error_messages() as $err )
458 echo "<li>$err</li>\n";
464 if ( ! empty($messages) ) {
465 foreach ( $messages as $msg )
472 echo esc_html( $title );
473 if ( current_user_can( 'create_users' ) ) { ?>
474 <a href="user-new.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
475 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
476 <a href="user-new.php" class="page-title-action"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a>
480 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( $usersearch ) ); ?>
483 <?php $wp_list_table->views(); ?>
487 <?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
489 <?php $wp_list_table->display(); ?>
497 } // end of the $doaction switch
499 include( ABSPATH . 'wp-admin/admin-footer.php' );