3 * Users administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once( './admin.php' );
12 if ( ! current_user_can( 'list_users' ) )
13 wp_die( __( 'Cheatin’ uh?' ) );
15 $wp_list_table = _get_list_table('WP_Users_List_Table');
16 $pagenum = $wp_list_table->get_pagenum();
18 $parent_file = 'users.php';
20 add_screen_option( 'per_page', array('label' => _x( 'Users', 'users per page (screen options)' )) );
22 // contextual help - choose Help on the top right of admin panel to preview this.
23 get_current_screen()->add_help_tab( array(
25 'title' => __('Overview'),
26 '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>' .
27 '<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>'
30 get_current_screen()->add_help_tab( array(
31 'id' => 'screen-display',
32 'title' => __('Screen Display'),
33 'content' => '<p>' . __('You can customize the display of this screen in a number of ways:') . '</p>' .
35 '<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>' .
36 '<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>' .
37 '<li>' . __('You can view all posts made by a user by clicking on the number under the Posts column.') . '</li>' .
41 $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>' .
43 '<li>' . __('Edit takes you to the editable profile screen for that user. You can also reach that screen by clicking on the username.') . '</li>';
46 $help .= '<li>' . __( 'Remove allows you to remove a user from your site. It does not delete their posts. You can also remove multiple users at once by using Bulk Actions.' ) . '</li>';
48 $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 posts. You can also delete multiple users at once by using Bulk Actions.' ) . '</li>';
52 get_current_screen()->add_help_tab( array(
54 'title' => __('Actions'),
59 get_current_screen()->set_help_sidebar(
60 '<p><strong>' . __('For more information:') . '</strong></p>' .
61 '<p>' . __('<a href="http://codex.wordpress.org/Users_Screen" target="_blank">Documentation on Managing Users</a>') . '</p>' .
62 '<p>' . __('<a href="http://codex.wordpress.org/Roles_and_Capabilities" target="_blank">Descriptions of Roles and Capabilities</a>') . '</p>' .
63 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
66 if ( empty($_REQUEST) ) {
67 $referer = '<input type="hidden" name="wp_http_referer" value="'. esc_attr(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
68 } elseif ( isset($_REQUEST['wp_http_referer']) ) {
69 $redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), stripslashes($_REQUEST['wp_http_referer']));
70 $referer = '<input type="hidden" name="wp_http_referer" value="' . esc_attr($redirect) . '" />';
72 $redirect = 'users.php';
78 switch ( $wp_list_table->current_action() ) {
80 /* Bulk Dropdown menu Role changes */
82 check_admin_referer('bulk-users');
84 if ( ! current_user_can( 'promote_users' ) )
85 wp_die( __( 'You can’t edit that user.' ) );
87 if ( empty($_REQUEST['users']) ) {
88 wp_redirect($redirect);
92 $editable_roles = get_editable_roles();
93 if ( empty( $editable_roles[$_REQUEST['new_role']] ) )
94 wp_die(__('You can’t give users that role.'));
96 $userids = $_REQUEST['users'];
98 foreach ( $userids as $id ) {
101 if ( ! current_user_can('promote_user', $id) )
102 wp_die(__('You can’t edit that user.'));
103 // The new role of the current user must also have the promote_users cap or be a multisite super admin
104 if ( $id == $current_user->ID && ! $wp_roles->role_objects[ $_REQUEST['new_role'] ]->has_cap('promote_users')
105 && ! ( is_multisite() && is_super_admin() ) ) {
106 $update = 'err_admin_role';
110 // If the user doesn't already belong to the blog, bail.
111 if ( is_multisite() && !is_user_member_of_blog( $id ) )
112 wp_die(__('Cheatin’ uh?'));
114 $user = new WP_User($id);
115 $user->set_role($_REQUEST['new_role']);
118 wp_redirect(add_query_arg('update', $update, $redirect));
124 if ( is_multisite() )
125 wp_die( __('User deletion is not allowed from this screen.') );
127 check_admin_referer('delete-users');
129 if ( empty($_REQUEST['users']) ) {
130 wp_redirect($redirect);
134 if ( ! current_user_can( 'delete_users' ) )
135 wp_die(__('You can’t delete users.'));
137 $userids = $_REQUEST['users'];
141 foreach ( (array) $userids as $id) {
144 if ( ! current_user_can( 'delete_user', $id ) )
145 wp_die(__( 'You can’t delete that user.' ) );
147 if ( $id == $current_user->ID ) {
148 $update = 'err_admin_del';
151 switch ( $_REQUEST['delete_option'] ) {
153 if ( current_user_can('delete_user', $id) )
157 if ( current_user_can('delete_user', $id) )
158 wp_delete_user($id, $_REQUEST['reassign_user']);
164 $redirect = add_query_arg( array('delete_count' => $delete_count, 'update' => $update), $redirect);
165 wp_redirect($redirect);
171 if ( is_multisite() )
172 wp_die( __('User deletion is not allowed from this screen.') );
174 check_admin_referer('bulk-users');
176 if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) {
177 wp_redirect($redirect);
181 if ( ! current_user_can( 'delete_users' ) )
182 $errors = new WP_Error( 'edit_users', __( 'You can’t delete users.' ) );
184 if ( empty($_REQUEST['users']) )
185 $userids = array(intval($_REQUEST['user']));
187 $userids = (array) $_REQUEST['users'];
189 include ('admin-header.php');
191 <form action="" method="post" name="updateusers" id="updateusers">
192 <?php wp_nonce_field('delete-users') ?>
193 <?php echo $referer; ?>
196 <?php screen_icon(); ?>
197 <h2><?php _e('Delete Users'); ?></h2>
198 <p><?php echo _n( 'You have specified this user for deletion:', 'You have specified these users for deletion:', count( $userids ) ); ?></p>
202 foreach ( $userids as $id ) {
204 $user = new WP_User($id);
205 if ( $id == $current_user->ID ) {
206 echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
208 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "</li>\n";
214 <?php if ( $go_delete ) : ?>
215 <fieldset><p><legend><?php echo _n( 'What should be done with posts and links owned by this user?', 'What should be done with posts and links owned by these users?', $go_delete ); ?></legend></p>
216 <ul style="list-style:none;">
217 <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" checked="checked" />
218 <?php _e('Delete all posts and links.'); ?></label></li>
219 <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
220 <?php echo '<label for="delete_option1">'.__('Attribute all posts and links to:').'</label>';
221 wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
223 <input type="hidden" name="action" value="dodelete" />
224 <?php submit_button( __('Confirm Deletion'), 'secondary' ); ?>
226 <p><?php _e('There are no valid users selected for deletion.'); ?></p>
235 check_admin_referer('remove-users');
237 if ( ! is_multisite() )
238 wp_die( __( 'You can’t remove users.' ) );
240 if ( empty($_REQUEST['users']) ) {
241 wp_redirect($redirect);
245 if ( ! current_user_can( 'remove_users' ) )
246 wp_die( __( 'You can’t remove users.' ) );
248 $userids = $_REQUEST['users'];
251 foreach ( $userids as $id ) {
253 if ( $id == $current_user->ID && !is_super_admin() ) {
254 $update = 'err_admin_remove';
257 if ( !current_user_can('remove_user', $id) ) {
258 $update = 'err_admin_remove';
261 remove_user_from_blog($id, $blog_id);
264 $redirect = add_query_arg( array('update' => $update), $redirect);
265 wp_redirect($redirect);
272 check_admin_referer('bulk-users');
274 if ( ! is_multisite() )
275 wp_die( __( 'You can’t remove users.' ) );
277 if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) {
278 wp_redirect($redirect);
282 if ( !current_user_can('remove_users') )
283 $error = new WP_Error('edit_users', __('You can’t remove users.'));
285 if ( empty($_REQUEST['users']) )
286 $userids = array(intval($_REQUEST['user']));
288 $userids = $_REQUEST['users'];
290 include ('admin-header.php');
292 <form action="" method="post" name="updateusers" id="updateusers">
293 <?php wp_nonce_field('remove-users') ?>
294 <?php echo $referer; ?>
297 <?php screen_icon(); ?>
298 <h2><?php _e('Remove Users from Site'); ?></h2>
299 <p><?php _e('You have specified these users for removal:'); ?></p>
303 foreach ( $userids as $id ) {
305 $user = new WP_User($id);
306 if ( $id == $current_user->ID && !is_super_admin() ) {
307 echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
308 } elseif ( !current_user_can('remove_user', $id) ) {
309 echo "<li>" . sprintf(__('ID #%1s: %2s <strong>You don\'t have permission to remove this user.</strong>'), $id, $user->user_login) . "</li>\n";
311 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "</li>\n";
316 <?php if ( $go_remove ) : ?>
317 <input type="hidden" name="action" value="doremove" />
318 <?php submit_button( __('Confirm Removal'), 'secondary' ); ?>
320 <p><?php _e('There are no valid users selected for removal.'); ?></p>
330 if ( !empty($_GET['_wp_http_referer']) ) {
331 wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
335 $wp_list_table->prepare_items();
336 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
337 if ( $pagenum > $total_pages && $total_pages > 0 ) {
338 wp_redirect( add_query_arg( 'paged', $total_pages ) );
342 include('./admin-header.php');
345 if ( isset($_GET['update']) ) :
346 switch($_GET['update']) {
349 $delete_count = isset($_GET['delete_count']) ? (int) $_GET['delete_count'] : 0;
350 $messages[] = '<div id="message" class="updated"><p>' . sprintf( _n( 'User deleted.', '%s users deleted.', $delete_count ), number_format_i18n( $delete_count ) ) . '</p></div>';
353 if ( isset( $_GET['id'] ) && ( $user_id = $_GET['id'] ) && current_user_can( 'edit_user', $user_id ) ) {
354 $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( 'New user created. <a href="%s">Edit user</a>' ),
355 esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ),
356 self_admin_url( 'user-edit.php?user_id=' . $user_id ) ) ) ) . '</p></div>';
358 $messages[] = '<div id="message" class="updated"><p>' . __( 'New user created.' ) . '</p></div>';
362 $messages[] = '<div id="message" class="updated"><p>' . __('Changed roles.') . '</p></div>';
364 case 'err_admin_role':
365 $messages[] = '<div id="message" class="error"><p>' . __('The current user’s role must have user editing capabilities.') . '</p></div>';
366 $messages[] = '<div id="message" class="updated"><p>' . __('Other user roles have been changed.') . '</p></div>';
368 case 'err_admin_del':
369 $messages[] = '<div id="message" class="error"><p>' . __('You can’t delete the current user.') . '</p></div>';
370 $messages[] = '<div id="message" class="updated"><p>' . __('Other users have been deleted.') . '</p></div>';
373 $messages[] = '<div id="message" class="updated fade"><p>' . __('User removed from this site.') . '</p></div>';
375 case 'err_admin_remove':
376 $messages[] = '<div id="message" class="error"><p>' . __("You can't remove the current user.") . '</p></div>';
377 $messages[] = '<div id="message" class="updated fade"><p>' . __('Other users have been removed.') . '</p></div>';
382 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?>
386 foreach ( $errors->get_error_messages() as $err )
387 echo "<li>$err</li>\n";
393 if ( ! empty($messages) ) {
394 foreach ( $messages as $msg )
399 <?php screen_icon(); ?>
402 echo esc_html( $title );
403 if ( current_user_can( 'create_users' ) ) { ?>
404 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
405 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
406 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a>
410 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( $usersearch ) ); ?>
413 <?php $wp_list_table->views(); ?>
415 <form action="" method="get">
417 <?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
419 <?php $wp_list_table->display(); ?>
427 } // end of the $doaction switch
429 include('./admin-footer.php');