Make WordPress Core


Ignore:
Timestamp:
03/02/2025 11:33:56 PM (13 months ago)
Author:
peterwilsoncc
Message:

Users: Use editable_roles filter for multisite sub-sites.

Adds a check of the editable_roles filter when adding users to a multisite sub-site to ensure the role is permitted to be used on the network. If the role is blocked by the filter, attempting to add the role will trigger a wp_die() similar to attempting to add a user with the role on a single site install.

Props eartboard, hareesh-pillai, ideag, sukhendu2002, spacedmonkey, thomaswm.
Fixes #43251.

File:
1 edited

Legend:

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

    r58132 r59901  
    11731173        '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support forums</a>' ) . '</p>';
    11741174}
     1175
     1176/**
     1177 * Stop execution if the role can not be assigned by the current user.
     1178 *
     1179 * @since 6.8.0
     1180 *
     1181 * @param string $role Role the user is attempting to assign.
     1182 */
     1183function wp_ensure_editable_role( $role ) {
     1184    $roles = get_editable_roles();
     1185    if ( ! isset( $roles[ $role ] ) ) {
     1186        wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
     1187    }
     1188}
Note: See TracChangeset for help on using the changeset viewer.