129 if ( empty($_REQUEST['users']) ) { |
145 if ( empty($_REQUEST['users']) ) { |
130 wp_redirect($redirect); |
146 wp_redirect($redirect); |
131 exit(); |
147 exit(); |
132 } |
148 } |
133 |
149 |
|
150 $userids = array_map( 'intval', (array) $_REQUEST['users'] ); |
|
151 |
|
152 if ( empty( $_REQUEST['delete_option'] ) ) { |
|
153 $url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $userids ) . '&error=true' ); |
|
154 $url = str_replace( '&', '&', wp_nonce_url( $url, 'bulk-users' ) ); |
|
155 wp_redirect( $url ); |
|
156 exit; |
|
157 } |
|
158 |
134 if ( ! current_user_can( 'delete_users' ) ) |
159 if ( ! current_user_can( 'delete_users' ) ) |
135 wp_die(__('You can’t delete users.')); |
160 wp_die(__('You can’t delete users.')); |
136 |
161 |
137 $userids = $_REQUEST['users']; |
|
138 $update = 'del'; |
162 $update = 'del'; |
139 $delete_count = 0; |
163 $delete_count = 0; |
140 |
164 |
141 foreach ( (array) $userids as $id) { |
165 foreach ( $userids as $id ) { |
142 $id = (int) $id; |
|
143 |
|
144 if ( ! current_user_can( 'delete_user', $id ) ) |
166 if ( ! current_user_can( 'delete_user', $id ) ) |
145 wp_die(__( 'You can’t delete that user.' ) ); |
167 wp_die(__( 'You can’t delete that user.' ) ); |
146 |
168 |
147 if ( $id == $current_user->ID ) { |
169 if ( $id == $current_user->ID ) { |
148 $update = 'err_admin_del'; |
170 $update = 'err_admin_del'; |
149 continue; |
171 continue; |
150 } |
172 } |
151 switch ( $_REQUEST['delete_option'] ) { |
173 switch ( $_REQUEST['delete_option'] ) { |
152 case 'delete': |
174 case 'delete': |
153 if ( current_user_can('delete_user', $id) ) |
175 wp_delete_user( $id ); |
154 wp_delete_user($id); |
|
155 break; |
176 break; |
156 case 'reassign': |
177 case 'reassign': |
157 if ( current_user_can('delete_user', $id) ) |
178 wp_delete_user( $id, $_REQUEST['reassign_user'] ); |
158 wp_delete_user($id, $_REQUEST['reassign_user']); |
|
159 break; |
179 break; |
160 } |
180 } |
161 ++$delete_count; |
181 ++$delete_count; |
162 } |
182 } |
163 |
183 |
180 |
200 |
181 if ( ! current_user_can( 'delete_users' ) ) |
201 if ( ! current_user_can( 'delete_users' ) ) |
182 $errors = new WP_Error( 'edit_users', __( 'You can’t delete users.' ) ); |
202 $errors = new WP_Error( 'edit_users', __( 'You can’t delete users.' ) ); |
183 |
203 |
184 if ( empty($_REQUEST['users']) ) |
204 if ( empty($_REQUEST['users']) ) |
185 $userids = array(intval($_REQUEST['user'])); |
205 $userids = array( intval( $_REQUEST['user'] ) ); |
186 else |
206 else |
187 $userids = (array) $_REQUEST['users']; |
207 $userids = array_map( 'intval', (array) $_REQUEST['users'] ); |
|
208 |
|
209 add_action( 'admin_head', 'delete_users_add_js' ); |
188 |
210 |
189 include ('admin-header.php'); |
211 include ('admin-header.php'); |
190 ?> |
212 ?> |
191 <form action="" method="post" name="updateusers" id="updateusers"> |
213 <form action="" method="post" name="updateusers" id="updateusers"> |
192 <?php wp_nonce_field('delete-users') ?> |
214 <?php wp_nonce_field('delete-users') ?> |
193 <?php echo $referer; ?> |
215 <?php echo $referer; ?> |
194 |
216 |
195 <div class="wrap"> |
217 <div class="wrap"> |
196 <?php screen_icon(); ?> |
218 <?php screen_icon(); ?> |
197 <h2><?php _e('Delete Users'); ?></h2> |
219 <h2><?php _e('Delete Users'); ?></h2> |
|
220 <?php if ( isset( $_REQUEST['error'] ) ) : ?> |
|
221 <div class="error"> |
|
222 <p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'Please select an option.' ); ?></p> |
|
223 </div> |
|
224 <?php endif; ?> |
198 <p><?php echo _n( 'You have specified this user for deletion:', 'You have specified these users for deletion:', count( $userids ) ); ?></p> |
225 <p><?php echo _n( 'You have specified this user for deletion:', 'You have specified these users for deletion:', count( $userids ) ); ?></p> |
199 <ul> |
226 <ul> |
200 <?php |
227 <?php |
201 $go_delete = 0; |
228 $go_delete = 0; |
202 foreach ( $userids as $id ) { |
229 foreach ( $userids as $id ) { |
203 $id = (int) $id; |
230 $user = get_userdata( $id ); |
204 $user = new WP_User($id); |
|
205 if ( $id == $current_user->ID ) { |
231 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"; |
232 echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n"; |
207 } else { |
233 } else { |
208 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "</li>\n"; |
234 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n"; |
209 $go_delete++; |
235 $go_delete++; |
210 } |
236 } |
211 } |
237 } |
212 ?> |
238 ?> |
213 </ul> |
239 </ul> |
214 <?php if ( $go_delete ) : ?> |
240 <?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> |
241 <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> |
216 <ul style="list-style:none;"> |
242 <ul style="list-style:none;"> |
217 <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" checked="checked" /> |
243 <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" /> |
218 <?php _e('Delete all posts and links.'); ?></label></li> |
244 <?php _e('Delete all posts.'); ?></label></li> |
219 <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" /> |
245 <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>'; |
246 <?php echo '<label for="delete_option1">' . __( 'Attribute all posts to:' ) . '</label> '; |
221 wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li> |
247 wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li> |
222 </ul></fieldset> |
248 </ul></fieldset> |
223 <input type="hidden" name="action" value="dodelete" /> |
249 <input type="hidden" name="action" value="dodelete" /> |
224 <?php submit_button( __('Confirm Deletion'), 'secondary' ); ?> |
250 <?php submit_button( __('Confirm Deletion'), 'secondary' ); ?> |
225 <?php else : ?> |
251 <?php else : ?> |
300 <ul> |
326 <ul> |
301 <?php |
327 <?php |
302 $go_remove = false; |
328 $go_remove = false; |
303 foreach ( $userids as $id ) { |
329 foreach ( $userids as $id ) { |
304 $id = (int) $id; |
330 $id = (int) $id; |
305 $user = new WP_User($id); |
331 $user = get_userdata( $id ); |
306 if ( $id == $current_user->ID && !is_super_admin() ) { |
332 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"; |
333 echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n"; |
308 } elseif ( !current_user_can('remove_user', $id) ) { |
334 } 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"; |
335 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"; |
310 } else { |
336 } else { |
311 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "</li>\n"; |
337 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n"; |
312 $go_remove = true; |
338 $go_remove = true; |
313 } |
339 } |
314 } |
340 } |
315 ?> |
341 ?> |
316 <?php if ( $go_remove ) : ?> |
342 <?php if ( $go_remove ) : ?> |