|
1 <?php |
|
2 /** |
|
3 * Users administration panel. |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Administration |
|
7 */ |
|
8 |
|
9 /** WordPress Administration Bootstrap */ |
|
10 require_once( dirname( __FILE__ ) . '/admin.php' ); |
|
11 |
|
12 if ( ! current_user_can( 'list_users' ) ) |
|
13 wp_die( __( 'Cheatin’ uh?' ) ); |
|
14 |
|
15 $wp_list_table = _get_list_table('WP_Users_List_Table'); |
|
16 $pagenum = $wp_list_table->get_pagenum(); |
|
17 $title = __('Users'); |
|
18 $parent_file = 'users.php'; |
|
19 |
|
20 add_screen_option( 'per_page', array('label' => _x( 'Users', 'users per page (screen options)' )) ); |
|
21 |
|
22 // contextual help - choose Help on the top right of admin panel to preview this. |
|
23 get_current_screen()->add_help_tab( array( |
|
24 'id' => 'overview', |
|
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>' |
|
28 ) ) ; |
|
29 |
|
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>' . |
|
34 '<ul>' . |
|
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>' . |
|
38 '</ul>' |
|
39 ) ); |
|
40 |
|
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>' . |
|
42 '<ul>' . |
|
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>'; |
|
44 |
|
45 if ( is_multisite() ) |
|
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>'; |
|
47 else |
|
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>'; |
|
49 |
|
50 $help .= '</ul>'; |
|
51 |
|
52 get_current_screen()->add_help_tab( array( |
|
53 'id' => 'actions', |
|
54 'title' => __('Actions'), |
|
55 'content' => $help, |
|
56 ) ); |
|
57 unset( $help ); |
|
58 |
|
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>' |
|
64 ); |
|
65 |
|
66 if ( empty($_REQUEST) ) { |
|
67 $referer = '<input type="hidden" name="wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />'; |
|
68 } elseif ( isset($_REQUEST['wp_http_referer']) ) { |
|
69 $redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), wp_unslash( $_REQUEST['wp_http_referer'] ) ); |
|
70 $referer = '<input type="hidden" name="wp_http_referer" value="' . esc_attr($redirect) . '" />'; |
|
71 } else { |
|
72 $redirect = 'users.php'; |
|
73 $referer = ''; |
|
74 } |
|
75 |
|
76 $update = ''; |
|
77 |
|
78 /** |
|
79 * @since 3.5.0 |
|
80 * @access private |
|
81 */ |
|
82 function delete_users_add_js() { ?> |
|
83 <script> |
|
84 jQuery(document).ready( function($) { |
|
85 var submit = $('#submit').prop('disabled', true); |
|
86 $('input[name=delete_option]').one('change', function() { |
|
87 submit.prop('disabled', false); |
|
88 }); |
|
89 $('#reassign_user').focus( function() { |
|
90 $('#delete_option1').prop('checked', true).trigger('change'); |
|
91 }); |
|
92 }); |
|
93 </script> |
|
94 <?php |
|
95 } |
|
96 |
|
97 switch ( $wp_list_table->current_action() ) { |
|
98 |
|
99 /* Bulk Dropdown menu Role changes */ |
|
100 case 'promote': |
|
101 check_admin_referer('bulk-users'); |
|
102 |
|
103 if ( ! current_user_can( 'promote_users' ) ) |
|
104 wp_die( __( 'You can’t edit that user.' ) ); |
|
105 |
|
106 if ( empty($_REQUEST['users']) ) { |
|
107 wp_redirect($redirect); |
|
108 exit(); |
|
109 } |
|
110 |
|
111 $editable_roles = get_editable_roles(); |
|
112 if ( empty( $editable_roles[$_REQUEST['new_role']] ) ) |
|
113 wp_die(__('You can’t give users that role.')); |
|
114 |
|
115 $userids = $_REQUEST['users']; |
|
116 $update = 'promote'; |
|
117 foreach ( $userids as $id ) { |
|
118 $id = (int) $id; |
|
119 |
|
120 if ( ! current_user_can('promote_user', $id) ) |
|
121 wp_die(__('You can’t edit that user.')); |
|
122 // The new role of the current user must also have the promote_users cap or be a multisite super admin |
|
123 if ( $id == $current_user->ID && ! $wp_roles->role_objects[ $_REQUEST['new_role'] ]->has_cap('promote_users') |
|
124 && ! ( is_multisite() && is_super_admin() ) ) { |
|
125 $update = 'err_admin_role'; |
|
126 continue; |
|
127 } |
|
128 |
|
129 // If the user doesn't already belong to the blog, bail. |
|
130 if ( is_multisite() && !is_user_member_of_blog( $id ) ) |
|
131 wp_die(__('Cheatin’ uh?')); |
|
132 |
|
133 $user = get_userdata( $id ); |
|
134 $user->set_role($_REQUEST['new_role']); |
|
135 } |
|
136 |
|
137 wp_redirect(add_query_arg('update', $update, $redirect)); |
|
138 exit(); |
|
139 |
|
140 break; |
|
141 |
|
142 case 'dodelete': |
|
143 if ( is_multisite() ) |
|
144 wp_die( __('User deletion is not allowed from this screen.') ); |
|
145 |
|
146 check_admin_referer('delete-users'); |
|
147 |
|
148 if ( empty($_REQUEST['users']) ) { |
|
149 wp_redirect($redirect); |
|
150 exit(); |
|
151 } |
|
152 |
|
153 $userids = array_map( 'intval', (array) $_REQUEST['users'] ); |
|
154 |
|
155 if ( empty( $_REQUEST['delete_option'] ) ) { |
|
156 $url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $userids ) . '&error=true' ); |
|
157 $url = str_replace( '&', '&', wp_nonce_url( $url, 'bulk-users' ) ); |
|
158 wp_redirect( $url ); |
|
159 exit; |
|
160 } |
|
161 |
|
162 if ( ! current_user_can( 'delete_users' ) ) |
|
163 wp_die(__('You can’t delete users.')); |
|
164 |
|
165 $update = 'del'; |
|
166 $delete_count = 0; |
|
167 |
|
168 foreach ( $userids as $id ) { |
|
169 if ( ! current_user_can( 'delete_user', $id ) ) |
|
170 wp_die(__( 'You can’t delete that user.' ) ); |
|
171 |
|
172 if ( $id == $current_user->ID ) { |
|
173 $update = 'err_admin_del'; |
|
174 continue; |
|
175 } |
|
176 switch ( $_REQUEST['delete_option'] ) { |
|
177 case 'delete': |
|
178 wp_delete_user( $id ); |
|
179 break; |
|
180 case 'reassign': |
|
181 wp_delete_user( $id, $_REQUEST['reassign_user'] ); |
|
182 break; |
|
183 } |
|
184 ++$delete_count; |
|
185 } |
|
186 |
|
187 $redirect = add_query_arg( array('delete_count' => $delete_count, 'update' => $update), $redirect); |
|
188 wp_redirect($redirect); |
|
189 exit(); |
|
190 |
|
191 break; |
|
192 |
|
193 case 'delete': |
|
194 if ( is_multisite() ) |
|
195 wp_die( __('User deletion is not allowed from this screen.') ); |
|
196 |
|
197 check_admin_referer('bulk-users'); |
|
198 |
|
199 if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) { |
|
200 wp_redirect($redirect); |
|
201 exit(); |
|
202 } |
|
203 |
|
204 if ( ! current_user_can( 'delete_users' ) ) |
|
205 $errors = new WP_Error( 'edit_users', __( 'You can’t delete users.' ) ); |
|
206 |
|
207 if ( empty($_REQUEST['users']) ) |
|
208 $userids = array( intval( $_REQUEST['user'] ) ); |
|
209 else |
|
210 $userids = array_map( 'intval', (array) $_REQUEST['users'] ); |
|
211 |
|
212 add_action( 'admin_head', 'delete_users_add_js' ); |
|
213 |
|
214 include( ABSPATH . 'wp-admin/admin-header.php' ); |
|
215 ?> |
|
216 <form action="" method="post" name="updateusers" id="updateusers"> |
|
217 <?php wp_nonce_field('delete-users') ?> |
|
218 <?php echo $referer; ?> |
|
219 |
|
220 <div class="wrap"> |
|
221 <?php screen_icon(); ?> |
|
222 <h2><?php _e('Delete Users'); ?></h2> |
|
223 <?php if ( isset( $_REQUEST['error'] ) ) : ?> |
|
224 <div class="error"> |
|
225 <p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'Please select an option.' ); ?></p> |
|
226 </div> |
|
227 <?php endif; ?> |
|
228 <p><?php echo _n( 'You have specified this user for deletion:', 'You have specified these users for deletion:', count( $userids ) ); ?></p> |
|
229 <ul> |
|
230 <?php |
|
231 $go_delete = 0; |
|
232 foreach ( $userids as $id ) { |
|
233 $user = get_userdata( $id ); |
|
234 if ( $id == $current_user->ID ) { |
|
235 echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n"; |
|
236 } else { |
|
237 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n"; |
|
238 $go_delete++; |
|
239 } |
|
240 } |
|
241 ?> |
|
242 </ul> |
|
243 <?php if ( $go_delete ) : ?> |
|
244 <fieldset><p><legend><?php echo _n( 'What should be done with posts owned by this user?', 'What should be done with posts owned by these users?', $go_delete ); ?></legend></p> |
|
245 <ul style="list-style:none;"> |
|
246 <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" /> |
|
247 <?php _e('Delete all posts.'); ?></label></li> |
|
248 <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" /> |
|
249 <?php echo '<label for="delete_option1">' . __( 'Attribute all posts to:' ) . '</label> '; |
|
250 wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li> |
|
251 </ul></fieldset> |
|
252 <input type="hidden" name="action" value="dodelete" /> |
|
253 <?php submit_button( __('Confirm Deletion'), 'secondary' ); ?> |
|
254 <?php else : ?> |
|
255 <p><?php _e('There are no valid users selected for deletion.'); ?></p> |
|
256 <?php endif; ?> |
|
257 </div> |
|
258 </form> |
|
259 <?php |
|
260 |
|
261 break; |
|
262 |
|
263 case 'doremove': |
|
264 check_admin_referer('remove-users'); |
|
265 |
|
266 if ( ! is_multisite() ) |
|
267 wp_die( __( 'You can’t remove users.' ) ); |
|
268 |
|
269 if ( empty($_REQUEST['users']) ) { |
|
270 wp_redirect($redirect); |
|
271 exit; |
|
272 } |
|
273 |
|
274 if ( ! current_user_can( 'remove_users' ) ) |
|
275 wp_die( __( 'You can’t remove users.' ) ); |
|
276 |
|
277 $userids = $_REQUEST['users']; |
|
278 |
|
279 $update = 'remove'; |
|
280 foreach ( $userids as $id ) { |
|
281 $id = (int) $id; |
|
282 if ( $id == $current_user->ID && !is_super_admin() ) { |
|
283 $update = 'err_admin_remove'; |
|
284 continue; |
|
285 } |
|
286 if ( !current_user_can('remove_user', $id) ) { |
|
287 $update = 'err_admin_remove'; |
|
288 continue; |
|
289 } |
|
290 remove_user_from_blog($id, $blog_id); |
|
291 } |
|
292 |
|
293 $redirect = add_query_arg( array('update' => $update), $redirect); |
|
294 wp_redirect($redirect); |
|
295 exit; |
|
296 |
|
297 break; |
|
298 |
|
299 case 'remove': |
|
300 |
|
301 check_admin_referer('bulk-users'); |
|
302 |
|
303 if ( ! is_multisite() ) |
|
304 wp_die( __( 'You can’t remove users.' ) ); |
|
305 |
|
306 if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) { |
|
307 wp_redirect($redirect); |
|
308 exit(); |
|
309 } |
|
310 |
|
311 if ( !current_user_can('remove_users') ) |
|
312 $error = new WP_Error('edit_users', __('You can’t remove users.')); |
|
313 |
|
314 if ( empty($_REQUEST['users']) ) |
|
315 $userids = array(intval($_REQUEST['user'])); |
|
316 else |
|
317 $userids = $_REQUEST['users']; |
|
318 |
|
319 include( ABSPATH . 'wp-admin/admin-header.php' ); |
|
320 ?> |
|
321 <form action="" method="post" name="updateusers" id="updateusers"> |
|
322 <?php wp_nonce_field('remove-users') ?> |
|
323 <?php echo $referer; ?> |
|
324 |
|
325 <div class="wrap"> |
|
326 <?php screen_icon(); ?> |
|
327 <h2><?php _e('Remove Users from Site'); ?></h2> |
|
328 <p><?php _e('You have specified these users for removal:'); ?></p> |
|
329 <ul> |
|
330 <?php |
|
331 $go_remove = false; |
|
332 foreach ( $userids as $id ) { |
|
333 $id = (int) $id; |
|
334 $user = get_userdata( $id ); |
|
335 if ( $id == $current_user->ID && !is_super_admin() ) { |
|
336 echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n"; |
|
337 } elseif ( !current_user_can('remove_user', $id) ) { |
|
338 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"; |
|
339 } else { |
|
340 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n"; |
|
341 $go_remove = true; |
|
342 } |
|
343 } |
|
344 ?> |
|
345 <?php if ( $go_remove ) : ?> |
|
346 <input type="hidden" name="action" value="doremove" /> |
|
347 <?php submit_button( __('Confirm Removal'), 'secondary' ); ?> |
|
348 <?php else : ?> |
|
349 <p><?php _e('There are no valid users selected for removal.'); ?></p> |
|
350 <?php endif; ?> |
|
351 </div> |
|
352 </form> |
|
353 <?php |
|
354 |
|
355 break; |
|
356 |
|
357 default: |
|
358 |
|
359 if ( !empty($_GET['_wp_http_referer']) ) { |
|
360 wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce'), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); |
|
361 exit; |
|
362 } |
|
363 |
|
364 $wp_list_table->prepare_items(); |
|
365 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
366 if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
367 wp_redirect( add_query_arg( 'paged', $total_pages ) ); |
|
368 exit; |
|
369 } |
|
370 |
|
371 include( ABSPATH . 'wp-admin/admin-header.php' ); |
|
372 |
|
373 $messages = array(); |
|
374 if ( isset($_GET['update']) ) : |
|
375 switch($_GET['update']) { |
|
376 case 'del': |
|
377 case 'del_many': |
|
378 $delete_count = isset($_GET['delete_count']) ? (int) $_GET['delete_count'] : 0; |
|
379 $messages[] = '<div id="message" class="updated"><p>' . sprintf( _n( 'User deleted.', '%s users deleted.', $delete_count ), number_format_i18n( $delete_count ) ) . '</p></div>'; |
|
380 break; |
|
381 case 'add': |
|
382 if ( isset( $_GET['id'] ) && ( $user_id = $_GET['id'] ) && current_user_can( 'edit_user', $user_id ) ) { |
|
383 $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( 'New user created. <a href="%s">Edit user</a>' ), |
|
384 esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), |
|
385 self_admin_url( 'user-edit.php?user_id=' . $user_id ) ) ) ) . '</p></div>'; |
|
386 } else { |
|
387 $messages[] = '<div id="message" class="updated"><p>' . __( 'New user created.' ) . '</p></div>'; |
|
388 } |
|
389 break; |
|
390 case 'promote': |
|
391 $messages[] = '<div id="message" class="updated"><p>' . __('Changed roles.') . '</p></div>'; |
|
392 break; |
|
393 case 'err_admin_role': |
|
394 $messages[] = '<div id="message" class="error"><p>' . __('The current user’s role must have user editing capabilities.') . '</p></div>'; |
|
395 $messages[] = '<div id="message" class="updated"><p>' . __('Other user roles have been changed.') . '</p></div>'; |
|
396 break; |
|
397 case 'err_admin_del': |
|
398 $messages[] = '<div id="message" class="error"><p>' . __('You can’t delete the current user.') . '</p></div>'; |
|
399 $messages[] = '<div id="message" class="updated"><p>' . __('Other users have been deleted.') . '</p></div>'; |
|
400 break; |
|
401 case 'remove': |
|
402 $messages[] = '<div id="message" class="updated fade"><p>' . __('User removed from this site.') . '</p></div>'; |
|
403 break; |
|
404 case 'err_admin_remove': |
|
405 $messages[] = '<div id="message" class="error"><p>' . __("You can't remove the current user.") . '</p></div>'; |
|
406 $messages[] = '<div id="message" class="updated fade"><p>' . __('Other users have been removed.') . '</p></div>'; |
|
407 break; |
|
408 } |
|
409 endif; ?> |
|
410 |
|
411 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?> |
|
412 <div class="error"> |
|
413 <ul> |
|
414 <?php |
|
415 foreach ( $errors->get_error_messages() as $err ) |
|
416 echo "<li>$err</li>\n"; |
|
417 ?> |
|
418 </ul> |
|
419 </div> |
|
420 <?php endif; |
|
421 |
|
422 if ( ! empty($messages) ) { |
|
423 foreach ( $messages as $msg ) |
|
424 echo $msg; |
|
425 } ?> |
|
426 |
|
427 <div class="wrap"> |
|
428 <?php screen_icon(); ?> |
|
429 <h2> |
|
430 <?php |
|
431 echo esc_html( $title ); |
|
432 if ( current_user_can( 'create_users' ) ) { ?> |
|
433 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a> |
|
434 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?> |
|
435 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a> |
|
436 <?php } |
|
437 |
|
438 if ( $usersearch ) |
|
439 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( $usersearch ) ); ?> |
|
440 </h2> |
|
441 |
|
442 <?php $wp_list_table->views(); ?> |
|
443 |
|
444 <form action="" method="get"> |
|
445 |
|
446 <?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?> |
|
447 |
|
448 <?php $wp_list_table->display(); ?> |
|
449 </form> |
|
450 |
|
451 <br class="clear" /> |
|
452 </div> |
|
453 <?php |
|
454 break; |
|
455 |
|
456 } // end of the $doaction switch |
|
457 |
|
458 include( ABSPATH . 'wp-admin/admin-footer.php' ); |