wp_ensure_editable_role()WP 6.8.0

Stop execution if the role can not be assigned by the current user.

No Hooks.

Return

null. Nothing (null).

Usage

wp_ensure_editable_role( $role );
$role(string) (required)
Role the user is attempting to assign.

Changelog

Since 6.8.0 Introduced.

wp_ensure_editable_role() code WP 6.8

function wp_ensure_editable_role( $role ) {
	$roles = get_editable_roles();
	if ( ! isset( $roles[ $role ] ) ) {
		wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
	}
}