Skip to content

Commit

Permalink
When checking to see if a user has access to opt out of a feature, if…
Browse files Browse the repository at this point in the history
… they have no role set but are a super admin, set their role to administrator
  • Loading branch information
dkotter committed Feb 5, 2024
1 parent b33a8ac commit e8c37e7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions includes/Classifai/Admin/UserProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,19 @@ public function get_allowed_features( int $user_id ): array {

// Check if user has access to the feature by role.
$allowed_roles = $settings['roles'] ?? [];
if (
$role_based_access_enabled &&
! empty( $allowed_roles ) &&
! empty( array_intersect( $user_roles, $allowed_roles ) )
) {
$allowed_features[ $feature_class::ID ] = $feature_class->get_label();
continue;
if ( $role_based_access_enabled ) {
// For super admins that don't have a specific role on a site, treat them as admins.
if ( is_multisite() && is_super_admin( $user_id ) && empty( $user_roles ) ) {
$user_roles = [ 'administrator' ];
}

if (
! empty( $allowed_roles ) &&
! empty( array_intersect( $user_roles, $allowed_roles ) )
) {
$allowed_features[ $feature_class::ID ] = $feature_class->get_label();
continue;
}
}

// Check if user has access to the feature.
Expand Down

0 comments on commit e8c37e7

Please sign in to comment.