3 * Multisite users administration panel.
6 * @subpackage Multisite
10 /** Load WordPress Administration Bootstrap */
11 require_once( dirname( __FILE__ ) . '/admin.php' );
13 if ( ! is_multisite() )
14 wp_die( __( 'Multisite support is not enabled.' ) );
16 if ( ! current_user_can( 'manage_network_users' ) )
17 wp_die( __( 'You do not have permission to access this page.' ) );
19 function confirm_delete_users( $users ) {
20 $current_user = wp_get_current_user();
21 if ( !is_array( $users ) )
24 <h2><?php esc_html_e( 'Users' ); ?></h2>
25 <p><?php _e( 'Transfer or delete content before deleting users.' ); ?></p>
26 <form action="users.php?action=dodelete" method="post">
27 <input type="hidden" name="dodelete" />
29 wp_nonce_field( 'ms-users-delete' );
30 $site_admins = get_super_admins();
31 $admin_out = '<option value="' . $current_user->ID . '">' . $current_user->user_login . '</option>';
33 foreach ( ( $allusers = (array) $_POST['allusers'] ) as $user_id ) {
34 if ( $user_id != '' && $user_id != '0' ) {
35 $delete_user = get_userdata( $user_id );
37 if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
38 wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
40 if ( in_array( $delete_user->user_login, $site_admins ) )
41 wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ), $delete_user->user_login ) );
43 echo "<input type='hidden' name='user[]' value='{$user_id}'/>\n";
44 $blogs = get_blogs_of_user( $user_id, true );
46 if ( !empty( $blogs ) ) {
48 <br /><fieldset><p><legend><?php printf( __( "What should be done with content owned by %s?" ), '<em>' . $delete_user->user_login . '</em>' ); ?></legend></p>
50 foreach ( (array) $blogs as $key => $details ) {
51 $blog_users = get_users( array( 'blog_id' => $details->userblog_id, 'fields' => array( 'ID', 'user_login' ) ) );
52 if ( is_array( $blog_users ) && !empty( $blog_users ) ) {
53 $user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
54 $user_dropdown = "<select name='blog[$user_id][$key]'>";
56 foreach ( $blog_users as $user ) {
57 if ( ! in_array( $user->ID, $allusers ) )
58 $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
60 if ( '' == $user_list )
61 $user_list = $admin_out;
62 $user_dropdown .= $user_list;
63 $user_dropdown .= "</select>\n";
65 <ul style="list-style:none;">
66 <li><?php printf( __( 'Site: %s' ), $user_site ); ?></li>
67 <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" />
68 <?php _e( 'Delete all content.' ); ?></label></li>
69 <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" />
70 <?php echo __( 'Attribute all content to:' ) . '</label>' . $user_dropdown; ?></li>
80 /** This action is documented in wp-admin/users.php */
81 do_action( 'delete_user_form', $current_user );
83 submit_button( __('Confirm Deletion'), 'delete' );
90 if ( isset( $_GET['action'] ) ) {
91 /** This action is documented in wp-admin/network/edit.php */
92 do_action( 'wpmuadminedit' );
94 switch ( $_GET['action'] ) {
96 if ( ! current_user_can( 'manage_network_users' ) )
97 wp_die( __( 'You do not have permission to access this page.' ) );
99 check_admin_referer( 'deleteuser' );
101 $id = intval( $_GET['id'] );
102 if ( $id != '0' && $id != '1' ) {
103 $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
104 $title = __( 'Users' );
105 $parent_file = 'users.php';
106 require_once( ABSPATH . 'wp-admin/admin-header.php' );
107 echo '<div class="wrap">';
108 confirm_delete_users( $_POST['allusers'] );
110 require_once( ABSPATH . 'wp-admin/admin-footer.php' );
112 wp_redirect( network_admin_url( 'users.php' ) );
117 if ( !current_user_can( 'manage_network_users' ) )
118 wp_die( __( 'You do not have permission to access this page.' ) );
120 if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
121 check_admin_referer( 'bulk-users-network' );
123 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
126 foreach ( (array) $_POST['allusers'] as $user_id ) {
127 if ( !empty( $user_id ) ) {
128 switch ( $doaction ) {
130 if ( ! current_user_can( 'delete_users' ) )
131 wp_die( __( 'You do not have permission to access this page.' ) );
132 $title = __( 'Users' );
133 $parent_file = 'users.php';
134 require_once( ABSPATH . 'wp-admin/admin-header.php' );
135 echo '<div class="wrap">';
136 confirm_delete_users( $_POST['allusers'] );
138 require_once( ABSPATH . 'wp-admin/admin-footer.php' );
142 $user = get_userdata( $user_id );
143 if ( is_super_admin( $user->ID ) )
144 wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
146 $userfunction = 'all_spam';
147 $blogs = get_blogs_of_user( $user_id, true );
148 foreach ( (array) $blogs as $details ) {
149 if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
150 update_blog_status( $details->userblog_id, 'spam', '1' );
152 update_user_status( $user_id, 'spam', '1' );
156 $userfunction = 'all_notspam';
157 $blogs = get_blogs_of_user( $user_id, true );
158 foreach ( (array) $blogs as $details )
159 update_blog_status( $details->userblog_id, 'spam', '0' );
161 update_user_status( $user_id, 'spam', '0' );
167 wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
169 $location = network_admin_url( 'users.php' );
171 if ( ! empty( $_REQUEST['paged'] ) )
172 $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
173 wp_redirect( $location );
178 check_admin_referer( 'ms-users-delete' );
179 if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
180 wp_die( __( 'You do not have permission to access this page.' ) );
182 if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
183 foreach ( $_POST['blog'] as $id => $users ) {
184 foreach ( $users as $blogid => $user_id ) {
185 if ( ! current_user_can( 'delete_user', $id ) )
188 if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
189 remove_user_from_blog( $id, $blogid, $user_id );
191 remove_user_from_blog( $id, $blogid );
196 if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
197 foreach( $_POST['user'] as $id ) {
198 if ( ! current_user_can( 'delete_user', $id ) )
200 wpmu_delete_user( $id );
205 $deletefunction = 'delete';
207 $deletefunction = 'all_delete';
209 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
214 $wp_list_table = _get_list_table('WP_MS_Users_List_Table');
215 $pagenum = $wp_list_table->get_pagenum();
216 $wp_list_table->prepare_items();
217 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
219 if ( $pagenum > $total_pages && $total_pages > 0 ) {
220 wp_redirect( add_query_arg( 'paged', $total_pages ) );
223 $title = __( 'Users' );
224 $parent_file = 'users.php';
226 add_screen_option( 'per_page', array('label' => _x( 'Users', 'users per page (screen options)' )) );
228 get_current_screen()->add_help_tab( array(
230 'title' => __('Overview'),
232 '<p>' . __('This table shows all users across the network and the sites to which they are assigned.') . '</p>' .
233 '<p>' . __('Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to their Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.') . '</p>' .
234 '<p>' . __('You can also go to the user’s profile page by clicking on the individual username.') . '</p>' .
235 '<p>' . __('You can sort the table by clicking on any of the bold headings and switch between list and excerpt views by using the icons in the upper right.') . '</p>' .
236 '<p>' . __('The bulk action will permanently delete selected users, or mark/unmark those selected as spam. Spam users will have posts removed and will be unable to sign up again with the same email addresses.') . '</p>' .
237 '<p>' . __('You can make an existing user an additional super admin by going to the Edit User profile page and checking the box to grant that privilege.') . '</p>'
240 get_current_screen()->set_help_sidebar(
241 '<p><strong>' . __('For more information:') . '</strong></p>' .
242 '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' .
243 '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
246 require_once( ABSPATH . 'wp-admin/admin-header.php' );
248 if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
250 <div id="message" class="updated"><p>
252 switch ( $_REQUEST['action'] ) {
254 _e( 'User deleted.' );
257 _e( 'Users marked as spam.' );
260 _e( 'Users removed from spam.' );
263 _e( 'Users deleted.' );
275 <h2><?php esc_html_e( 'Users' );
276 if ( current_user_can( 'create_users') ) : ?>
277 <a href="<?php echo network_admin_url('user-new.php'); ?>" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a><?php
280 if ( !empty( $usersearch ) )
281 printf( '<span class="subtitle">' . __( 'Search results for “%s”' ) . '</span>', esc_html( $usersearch ) );
285 <?php $wp_list_table->views(); ?>
287 <form action="" method="get" class="search-form">
288 <?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?>
291 <form id="form-user-list" action="users.php?action=allusers" method="post">
292 <?php $wp_list_table->display(); ?>
296 <?php require_once( ABSPATH . 'wp-admin/admin-footer.php' ); ?>