WordPress.org

Make WordPress Core

Ticket #26195: 26195.diff

File 26195.diff, 4.2 KB (added by leewillis77, 6 years ago)
  • wp-admin/users.php

     
    152152
    153153        $userids = array_map( 'intval', (array) $_REQUEST['users'] );
    154154
    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 
    162155        if ( ! current_user_can( 'delete_users' ) )
    163156                wp_die(__('You can’t delete users.'));
    164157
    165158        $update = 'del';
    166159        $delete_count = 0;
     160        $delete_option = isset( $_REQUEST['delete_option'] ) ? $_REQUEST['delete_option'] : 'delete';
    167161
    168162        foreach ( $userids as $id ) {
    169163                if ( ! current_user_can( 'delete_user', $id ) )
     
    173167                        $update = 'err_admin_del';
    174168                        continue;
    175169                }
    176                 switch ( $_REQUEST['delete_option'] ) {
     170                switch ( $delete_option ) {
    177171                case 'delete':
    178172                        wp_delete_user( $id );
    179173                        break;
     
    209203        else
    210204                $userids = array_map( 'intval', (array) $_REQUEST['users'] );
    211205
    212         add_action( 'admin_head', 'delete_users_add_js' );
    213 
    214206        include( ABSPATH . 'wp-admin/admin-header.php' );
    215207?>
    216208<form action="" method="post" name="updateusers" id="updateusers">
     
    220212<div class="wrap">
    221213<?php screen_icon(); ?>
    222214<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; ?>
    228215<p><?php echo _n( 'You have specified this user for deletion:', 'You have specified these users for deletion:', count( $userids ) ); ?></p>
    229216<ul>
    230217<?php
    231218        $go_delete = 0;
     219        $have_posts = false;
    232220        foreach ( $userids as $id ) {
    233221                $user = get_userdata( $id );
    234222                if ( $id == $current_user->ID ) {
    235223                        echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
    236224                } else {
    237225                        echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n";
     226                        if ( ! $have_posts ) {
     227                                $post_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_author=%d", $id ) );
     228                                $have_posts = ( $post_count > 0 );
     229                        }
    238230                        $go_delete++;
    239231                }
    240232        }
    241233        ?>
    242234        </ul>
    243235<?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' ); ?>
     236        <?php if ( $have_posts ) : ?>
     237                <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>
     238                <ul style="list-style:none;">
     239                        <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" />
     240                        <?php _e('Delete all posts.'); ?></label></li>
     241                        <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
     242                        <?php echo '<label for="delete_option1">' . __( 'Attribute all posts to:' ) . '</label> ';
     243                        wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
     244                </ul></fieldset>
     245                <?php add_action( 'admin_head', 'delete_users_add_js' ); ?>
     246        <?php endif; ?>
     247                <input type="hidden" name="action" value="dodelete" />
     248                <?php submit_button( __('Confirm Deletion'), 'secondary' ); ?>
    254249<?php else : ?>
    255250        <p><?php _e('There are no valid users selected for deletion.'); ?></p>
    256251<?php endif; ?>