Changeset 59901
- Timestamp:
- 03/02/2025 11:33:56 PM (7 weeks ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ms.php
r58132 r59901 1173 1173 '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support forums</a>' ) . '</p>'; 1174 1174 } 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 */ 1183 function 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 } -
trunk/src/wp-admin/user-new.php
r59784 r59901 70 70 } else { 71 71 if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) { 72 73 wp_ensure_editable_role( $_REQUEST['role'] ); 74 72 75 $result = add_existing_user_to_blog( 73 76 array( … … 225 228 add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email. 226 229 } 230 231 wp_ensure_editable_role( $_REQUEST['role'] ); 227 232 228 233 wpmu_signup_user( -
trunk/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php
r51860 r59901 221 221 $this->assertContains( 'invalid_nonce', $valid['errors']->get_error_codes() ); 222 222 } 223 224 /** 225 * Ensure that wp_ensure_editable_role does not throw an exception when the role is editable. 226 * 227 * @ticket 43251 228 * 229 * @covers ::wp_ensure_editable_role 230 */ 231 public function test_wp_ensure_editable_role_allows_editable_roles() { 232 $role = get_role( 'editor' ); 233 $this->assertInstanceOf( 'WP_Role', $role, 'The editor role should exist.' ); 234 $this->assertNull( wp_ensure_editable_role( 'editor' ), 'The editor role should be editable.' ); 235 } 236 237 /** 238 * Ensure that wp_ensure_editable_role throws an exception for non-existent roles. 239 * 240 * @ticket 43251 241 * 242 * @covers ::wp_ensure_editable_role 243 */ 244 public function test_wp_ensure_editable_role_does_not_allow_non_existent_role() { 245 $this->expectException( 'WPDieException' ); 246 $role = get_role( 'non-existent-role' ); 247 $this->assertNotInstanceOf( 'WP_Role', $role, 'The non-existent-role role should not exist.' ); 248 wp_ensure_editable_role( 'non-existent-role' ); 249 } 250 251 /** 252 * Ensure that wp_ensure_editable_role throws an exception for roles that are not editable. 253 * 254 * @ticket 43251 255 * 256 * @covers ::wp_ensure_editable_role 257 */ 258 public function test_wp_ensure_editable_role_does_not_allow_uneditable_roles() { 259 add_filter( 260 'editable_roles', 261 function ( $roles ) { 262 unset( $roles['editor'] ); 263 return $roles; 264 } 265 ); 266 $this->expectException( 'WPDieException' ); 267 $role = get_role( 'editor' ); 268 $this->assertInstanceOf( 'WP_Role', $role, 'The editor role should exist.' ); 269 wp_ensure_editable_role( 'editor' ); 270 } 223 271 } 224 272
Note: See TracChangeset
for help on using the changeset viewer.