Skip to content

Commit debd1f5

Browse files
committed
Users: Disallow bulk editing a single user with no roles.
This changeset prevents users from removing their own role when bulk editing user roles. Props jomonthomaslobo1, johnbillion, hugod, audrasjb, shailu25, rishavdutta, rollybueno. Fixes #63068. git-svn-id: https://develop.svn.wordpress.org/trunk@62026 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 421ac36 commit debd1f5

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/wp-admin/users.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,18 @@
143143
wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
144144
}
145145

146-
// The new role of the current user must also have the promote_users cap or be a multisite super admin.
147-
if ( $id === $current_user->ID
148-
&& ! $wp_roles->role_objects[ $role ]->has_cap( 'promote_users' )
149-
&& ! ( is_multisite() && current_user_can( 'manage_network_users' ) )
150-
) {
151-
$update = 'err_admin_role';
146+
// The new role of the current user must also have the promote_users cap, be a multisite super admin and must not be empty.
147+
if ( $id === $current_user->ID ) {
148+
if ( '' === $role ) {
149+
wp_die( __( 'Sorry, you cannot remove your own role.' ), 403 );
150+
}
151+
152+
if ( $wp_roles->role_objects[ $role ]->has_cap( 'promote_users' ) || ( is_multisite() && current_user_can( 'manage_network_users' ) ) ) {
152153
continue;
154+
}
155+
156+
$update = 'err_admin_role';
157+
continue;
153158
}
154159

155160
// If the user doesn't already belong to the blog, bail.

0 commit comments

Comments
 (0)