Make WordPress Core

Changeset 62026


Ignore:
Timestamp:
03/14/2026 08:14:30 AM (4 months ago)
Author:
audrasjb
Message:

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.

File:
1 edited

Legend:

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

    r61854 r62026  
    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
Note: See TracChangeset for help on using the changeset viewer.