Make WordPress Core

Changeset 31656


Ignore:
Timestamp:
03/07/2015 04:39:13 AM (10 years ago)
Author:
jeremyfelt
Message:

Improve experience when deleting users from a multisite network.

When deleting a user who is not associated with any sites, the current messaging can be confusing as only users associated with at least one site actually appear on the confirmation page for deletion.

This experience can be improved by showing all users being deleted as well as their current site associations.

  • If an empty array of users is passed, don't attempt to confirm deletion.
  • If one user is passed, show a message crafted for a user of one.
  • If multiple users are passed, show a message crafted for many.
  • Show the pending results of all users to be deleted.
  • Update messaging around the deletion/confirmation process to be less misleading.

Props Idealien, HarishChaudhari, DrewAPicture.

Fixes #18132.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/network/users.php

    r31517 r31656  
    1919function confirm_delete_users( $users ) {
    2020    $current_user = wp_get_current_user();
    21     if ( !is_array( $users ) )
     21    if ( ! is_array( $users ) || empty( $users ) ) {
    2222        return false;
     23    }
    2324    ?>
    2425    <h2><?php esc_html_e( 'Users' ); ?></h2>
    25     <p><?php _e( 'Transfer or delete content before deleting users.' ); ?></p>
     26
     27    <?php if ( count( $users ) > 1 ) : ?>
     28        <p><?php _e( 'You have chosen to delete the following users from all networks and sites.' ); ?></p>
     29    <?php else : ?>
     30        <p><?php _e( 'You have chosen to delete the user from all networks and sites.' ); ?></p>
     31    <?php endif; ?>
     32   
    2633    <form action="users.php?action=dodelete" method="post">
    2734    <input type="hidden" name="dodelete" />
     
    2936    wp_nonce_field( 'ms-users-delete' );
    3037    $site_admins = get_super_admins();
    31     $admin_out = '<option value="' . $current_user->ID . '">' . $current_user->user_login . '</option>';
    32 
    33     foreach ( ( $allusers = (array) $_POST['allusers'] ) as $user_id ) {
     38    $admin_out = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>'; ?>
     39    <table class="form-table">
     40    <?php foreach ( ( $allusers = (array) $_POST['allusers'] ) as $user_id ) {
    3441        if ( $user_id != '' && $user_id != '0' ) {
    3542            $delete_user = get_userdata( $user_id );
    3643
    37             if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
     44            if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) {
    3845                wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
    39 
    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 ) );
    42 
    43             echo "<input type='hidden' name='user[]' value='{$user_id}'/>\n";
    44             $blogs = get_blogs_of_user( $user_id, true );
    45 
    46             if ( !empty( $blogs ) ) {
     46            }
     47
     48            if ( in_array( $delete_user->user_login, $site_admins ) ) {
     49                wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ), '<em>' . $delete_user->user_login . '</em>' ) );
     50            }
     51            ?>
     52            <tr>
     53                <th scope="row"><?php echo $delete_user->user_login; ?>
     54                    <?php echo '<input type="hidden" name="user[]" value="' . esc_attr( $user_id ) . '" />' . "\n"; ?>
     55                </th>
     56            <?php $blogs = get_blogs_of_user( $user_id, true );
     57
     58            if ( ! empty( $blogs ) ) {
    4759                ?>
    48                 <br /><fieldset><p><legend><?php printf( __( "What should be done with content owned by %s?" ), '<em>' . $delete_user->user_login . '</em>' ); ?></legend></p>
     60                <td><fieldset><p><legend><?php printf( __( 'What should be done with content owned by %s?' ), '<em>' . $delete_user->user_login . '</em>' ); ?></legend></p>
    4961                <?php
    5062                foreach ( (array) $blogs as $key => $details ) {
     
    5668                        $user_list = '';
    5769                        foreach ( $blog_users as $user ) {
    58                             if ( ! in_array( $user->ID, $allusers ) )
     70                            if ( ! in_array( $user->ID, $allusers ) ) {
    5971                                $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
     72                            }
    6073                        }
    61                         if ( '' == $user_list )
     74                        if ( '' == $user_list ) {
    6275                            $user_list = $admin_out;
     76                        }
    6377                        $user_dropdown .= $user_list;
    6478                        $user_dropdown .= "</select>\n";
     
    7488                    }
    7589                }
    76                 echo "</fieldset>";
    77             }
     90                echo "</fieldset></td></tr>";
     91            } else {
     92                ?>
     93                <td><fieldset><p><legend><?php _e( 'User has no sites or content and will be deleted.' ); ?></legend></p>
     94            <?php } ?>
     95            </tr>
     96        <?php
    7897        }
    7998    }
    8099
     100    ?>
     101    </table>
     102    <?php
    81103    /** This action is documented in wp-admin/users.php */
    82104    do_action( 'delete_user_form', $current_user );
    83105
     106    if ( count( $users ) > 1 ) : ?>
     107        <p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, these users will be permanently removed.' ); ?></p>
     108    <?php else : ?>
     109        <p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, the user will be permanently removed.' ); ?></p>
     110    <?php endif;
     111   
    84112    submit_button( __('Confirm Deletion'), 'delete' );
    85113    ?>
Note: See TracChangeset for help on using the changeset viewer.