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. Built from https://develop.svn.wordpress.org/trunk@31656 git-svn-id: http://core.svn.wordpress.org/trunk@31637 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
be207e6550
commit
63ceacb67a
|
@ -18,34 +18,46 @@ if ( ! current_user_can( 'manage_network_users' ) )
|
|||
|
||||
function confirm_delete_users( $users ) {
|
||||
$current_user = wp_get_current_user();
|
||||
if ( !is_array( $users ) )
|
||||
if ( ! is_array( $users ) || empty( $users ) ) {
|
||||
return false;
|
||||
}
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Users' ); ?></h2>
|
||||
<p><?php _e( 'Transfer or delete content before deleting users.' ); ?></p>
|
||||
|
||||
<?php if ( count( $users ) > 1 ) : ?>
|
||||
<p><?php _e( 'You have chosen to delete the following users from all networks and sites.' ); ?></p>
|
||||
<?php else : ?>
|
||||
<p><?php _e( 'You have chosen to delete the user from all networks and sites.' ); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="users.php?action=dodelete" method="post">
|
||||
<input type="hidden" name="dodelete" />
|
||||
<?php
|
||||
wp_nonce_field( 'ms-users-delete' );
|
||||
$site_admins = get_super_admins();
|
||||
$admin_out = '<option value="' . $current_user->ID . '">' . $current_user->user_login . '</option>';
|
||||
|
||||
foreach ( ( $allusers = (array) $_POST['allusers'] ) as $user_id ) {
|
||||
$admin_out = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>'; ?>
|
||||
<table class="form-table">
|
||||
<?php foreach ( ( $allusers = (array) $_POST['allusers'] ) as $user_id ) {
|
||||
if ( $user_id != '' && $user_id != '0' ) {
|
||||
$delete_user = get_userdata( $user_id );
|
||||
|
||||
if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
|
||||
if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) {
|
||||
wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
|
||||
}
|
||||
|
||||
if ( in_array( $delete_user->user_login, $site_admins ) )
|
||||
wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ), $delete_user->user_login ) );
|
||||
if ( in_array( $delete_user->user_login, $site_admins ) ) {
|
||||
wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ), '<em>' . $delete_user->user_login . '</em>' ) );
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<th scope="row"><?php echo $delete_user->user_login; ?>
|
||||
<?php echo '<input type="hidden" name="user[]" value="' . esc_attr( $user_id ) . '" />' . "\n"; ?>
|
||||
</th>
|
||||
<?php $blogs = get_blogs_of_user( $user_id, true );
|
||||
|
||||
echo "<input type='hidden' name='user[]' value='{$user_id}'/>\n";
|
||||
$blogs = get_blogs_of_user( $user_id, true );
|
||||
|
||||
if ( !empty( $blogs ) ) {
|
||||
if ( ! empty( $blogs ) ) {
|
||||
?>
|
||||
<br /><fieldset><p><legend><?php printf( __( "What should be done with content owned by %s?" ), '<em>' . $delete_user->user_login . '</em>' ); ?></legend></p>
|
||||
<td><fieldset><p><legend><?php printf( __( 'What should be done with content owned by %s?' ), '<em>' . $delete_user->user_login . '</em>' ); ?></legend></p>
|
||||
<?php
|
||||
foreach ( (array) $blogs as $key => $details ) {
|
||||
$blog_users = get_users( array( 'blog_id' => $details->userblog_id, 'fields' => array( 'ID', 'user_login' ) ) );
|
||||
|
@ -55,11 +67,13 @@ function confirm_delete_users( $users ) {
|
|||
$user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
|
||||
$user_list = '';
|
||||
foreach ( $blog_users as $user ) {
|
||||
if ( ! in_array( $user->ID, $allusers ) )
|
||||
if ( ! in_array( $user->ID, $allusers ) ) {
|
||||
$user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
|
||||
}
|
||||
}
|
||||
if ( '' == $user_list )
|
||||
if ( '' == $user_list ) {
|
||||
$user_list = $admin_out;
|
||||
}
|
||||
$user_dropdown .= $user_list;
|
||||
$user_dropdown .= "</select>\n";
|
||||
?>
|
||||
|
@ -73,14 +87,28 @@ function confirm_delete_users( $users ) {
|
|||
<?php
|
||||
}
|
||||
}
|
||||
echo "</fieldset>";
|
||||
}
|
||||
echo "</fieldset></td></tr>";
|
||||
} else {
|
||||
?>
|
||||
<td><fieldset><p><legend><?php _e( 'User has no sites or content and will be deleted.' ); ?></legend></p>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
/** This action is documented in wp-admin/users.php */
|
||||
do_action( 'delete_user_form', $current_user );
|
||||
|
||||
if ( count( $users ) > 1 ) : ?>
|
||||
<p><?php _e( 'Once you hit “Confirm Deletion”, these users will be permanently removed.' ); ?></p>
|
||||
<?php else : ?>
|
||||
<p><?php _e( 'Once you hit “Confirm Deletion”, the user will be permanently removed.' ); ?></p>
|
||||
<?php endif;
|
||||
|
||||
submit_button( __('Confirm Deletion'), 'delete' );
|
||||
?>
|
||||
</form>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.2-alpha-31655';
|
||||
$wp_version = '4.2-alpha-31656';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue