Make WordPress Core

Ticket #20045: 20045.diff

File 20045.diff, 3.9 KB (added by nacin, 13 years ago)

Based on the patches from Dan, Ben, and GhostToast.

  • wp-admin/users.php

     
    7575
    7676$update = '';
    7777
     78/**
     79 * @since 3.5.0
     80 * @access private
     81 */
     82function delete_users_add_js() { ?>
     83<script>
     84jQuery(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});
     90</script>
     91<?php
     92}
     93
    7894switch ( $wp_list_table->current_action() ) {
    7995
    8096/* Bulk Dropdown menu Role changes */
     
    131147                exit();
    132148        }
    133149
     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( '&amp;', '&', wp_nonce_url( $url, 'bulk-users' ) );
     155                wp_redirect( $url );
     156                exit;
     157        }
     158
    134159        if ( ! current_user_can( 'delete_users' ) )
    135160                wp_die(__('You can&#8217;t delete users.'));
    136161
    137         $userids = $_REQUEST['users'];
    138162        $update = 'del';
    139163        $delete_count = 0;
    140164
    141         foreach ( (array) $userids as $id) {
    142                 $id = (int) $id;
    143 
     165        foreach ( $userids as $id) {
    144166                if ( ! current_user_can( 'delete_user', $id ) )
    145167                        wp_die(__( 'You can&#8217;t delete that user.' ) );
    146168
     
    150172                }
    151173                switch ( $_REQUEST['delete_option'] ) {
    152174                case 'delete':
    153                         if ( current_user_can('delete_user', $id) )
    154                                 wp_delete_user($id);
     175                        wp_delete_user( $id );
    155176                        break;
    156177                case 'reassign':
    157                         if ( current_user_can('delete_user', $id) )
    158                                 wp_delete_user($id, $_REQUEST['reassign_user']);
     178                        wp_delete_user( $id, $_REQUEST['reassign_user'] );
    159179                        break;
    160180                }
    161181                ++$delete_count;
     
    182202                $errors = new WP_Error( 'edit_users', __( 'You can&#8217;t delete users.' ) );
    183203
    184204        if ( empty($_REQUEST['users']) )
    185                 $userids = array(intval($_REQUEST['user']));
     205                $userids = array( intval( $_REQUEST['user'] ) );
    186206        else
    187                 $userids = (array) $_REQUEST['users'];
     207                $userids = array_map( 'intval', (array) $_REQUEST['users'] );
    188208
     209        add_action( 'admin_head', 'delete_users_add_js' );
     210
    189211        include ('admin-header.php');
    190212?>
    191213<form action="" method="post" name="updateusers" id="updateusers">
     
    195217<div class="wrap">
    196218<?php screen_icon(); ?>
    197219<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; ?>
    198225<p><?php echo _n( 'You have specified this user for deletion:', 'You have specified these users for deletion:', count( $userids ) ); ?></p>
    199226<ul>
    200227<?php
    201228        $go_delete = 0;
    202229        foreach ( $userids as $id ) {
    203                 $id = (int) $id;
    204230                $user = get_userdata( $id );
    205231                if ( $id == $current_user->ID ) {
    206232                        echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
     
    214240<?php if ( $go_delete ) : ?>
    215241        <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>
    216242        <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" />
    218244                <?php _e('Delete all posts.'); ?></label></li>
    219245                <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
    220                 <?php echo '<label for="delete_option1">'.__('Attribute all posts to:').'</label>';
     246                <?php echo '<label for="delete_option1">' . __( 'Attribute all posts to:' ) . '</label> ';
    221247                wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
    222248        </ul></fieldset>
    223249        <input type="hidden" name="action" value="dodelete" />