$update = '';
+/**
+ * @since 3.5.0
+ * @access private
+ */
+function delete_users_add_js() { ?>
+<script>
+jQuery(document).ready( function($) {
+ var submit = $('#submit').prop('disabled', true);
+ $('input[name=delete_option]').one('change', function() {
+ submit.prop('disabled', false);
+ });
+});
+</script>
+<?php
+}
+
switch ( $wp_list_table->current_action() ) {
/* Bulk Dropdown menu Role changes */
if ( is_multisite() && !is_user_member_of_blog( $id ) )
wp_die(__('Cheatin’ uh?'));
- $user = new WP_User($id);
+ $user = get_userdata( $id );
$user->set_role($_REQUEST['new_role']);
}
exit();
}
+ $userids = array_map( 'intval', (array) $_REQUEST['users'] );
+
+ if ( empty( $_REQUEST['delete_option'] ) ) {
+ $url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $userids ) . '&error=true' );
+ $url = str_replace( '&', '&', wp_nonce_url( $url, 'bulk-users' ) );
+ wp_redirect( $url );
+ exit;
+ }
+
if ( ! current_user_can( 'delete_users' ) )
wp_die(__('You can’t delete users.'));
- $userids = $_REQUEST['users'];
$update = 'del';
$delete_count = 0;
- foreach ( (array) $userids as $id) {
- $id = (int) $id;
-
+ foreach ( $userids as $id ) {
if ( ! current_user_can( 'delete_user', $id ) )
wp_die(__( 'You can’t delete that user.' ) );
}
switch ( $_REQUEST['delete_option'] ) {
case 'delete':
- if ( current_user_can('delete_user', $id) )
- wp_delete_user($id);
+ wp_delete_user( $id );
break;
case 'reassign':
- if ( current_user_can('delete_user', $id) )
- wp_delete_user($id, $_REQUEST['reassign_user']);
+ wp_delete_user( $id, $_REQUEST['reassign_user'] );
break;
}
++$delete_count;
$errors = new WP_Error( 'edit_users', __( 'You can’t delete users.' ) );
if ( empty($_REQUEST['users']) )
- $userids = array(intval($_REQUEST['user']));
+ $userids = array( intval( $_REQUEST['user'] ) );
else
- $userids = (array) $_REQUEST['users'];
+ $userids = array_map( 'intval', (array) $_REQUEST['users'] );
+
+ add_action( 'admin_head', 'delete_users_add_js' );
include ('admin-header.php');
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php _e('Delete Users'); ?></h2>
+<?php if ( isset( $_REQUEST['error'] ) ) : ?>
+<div class="error">
+ <p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'Please select an option.' ); ?></p>
+</div>
+<?php endif; ?>
<p><?php echo _n( 'You have specified this user for deletion:', 'You have specified these users for deletion:', count( $userids ) ); ?></p>
<ul>
<?php
$go_delete = 0;
foreach ( $userids as $id ) {
- $id = (int) $id;
- $user = new WP_User($id);
+ $user = get_userdata( $id );
if ( $id == $current_user->ID ) {
- echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
+ echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
} else {
- echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "</li>\n";
+ echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n";
$go_delete++;
}
}
?>
</ul>
<?php if ( $go_delete ) : ?>
- <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>
+ <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>
<ul style="list-style:none;">
- <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" checked="checked" />
- <?php _e('Delete all posts and links.'); ?></label></li>
+ <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" />
+ <?php _e('Delete all posts.'); ?></label></li>
<li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
- <?php echo '<label for="delete_option1">'.__('Attribute all posts and links to:').'</label>';
+ <?php echo '<label for="delete_option1">' . __( 'Attribute all posts to:' ) . '</label> ';
wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
</ul></fieldset>
<input type="hidden" name="action" value="dodelete" />
$go_remove = false;
foreach ( $userids as $id ) {
$id = (int) $id;
- $user = new WP_User($id);
+ $user = get_userdata( $id );
if ( $id == $current_user->ID && !is_super_admin() ) {
- echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
+ echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
} elseif ( !current_user_can('remove_user', $id) ) {
- echo "<li>" . sprintf(__('ID #%1s: %2s <strong>You don\'t have permission to remove this user.</strong>'), $id, $user->user_login) . "</li>\n";
+ 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";
} else {
- echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "</li>\n";
+ echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n";
$go_remove = true;
}
}