Skip to content

Commit f5e9c60

Browse files
authored
Merge pull request #689 from 10up/fix/658
For super admins with no role set, treat them as administrators
2 parents 0180001 + e8c37e7 commit f5e9c60

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

includes/Classifai/Admin/UserProfile.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,19 @@ public function get_allowed_features( int $user_id ): array {
158158

159159
// Check if user has access to the feature by role.
160160
$allowed_roles = $settings['roles'] ?? [];
161-
if (
162-
$role_based_access_enabled &&
163-
! empty( $allowed_roles ) &&
164-
! empty( array_intersect( $user_roles, $allowed_roles ) )
165-
) {
166-
$allowed_features[ $feature_class::ID ] = $feature_class->get_label();
167-
continue;
161+
if ( $role_based_access_enabled ) {
162+
// For super admins that don't have a specific role on a site, treat them as admins.
163+
if ( is_multisite() && is_super_admin( $user_id ) && empty( $user_roles ) ) {
164+
$user_roles = [ 'administrator' ];
165+
}
166+
167+
if (
168+
! empty( $allowed_roles ) &&
169+
! empty( array_intersect( $user_roles, $allowed_roles ) )
170+
) {
171+
$allowed_features[ $feature_class::ID ] = $feature_class->get_label();
172+
continue;
173+
}
168174
}
169175

170176
// Check if user has access to the feature.

includes/Classifai/Features/Feature.php

+5
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,11 @@ public function has_access(): bool {
938938
* Checks if Role-based access is enabled and user role has access to the feature.
939939
*/
940940
if ( $role_based_access_enabled ) {
941+
// For super admins that don't have a specific role on a site, treat them as admins.
942+
if ( is_multisite() && is_super_admin( $user_id ) && empty( $user_roles ) ) {
943+
$user_roles = [ 'administrator' ];
944+
}
945+
941946
$access = ( ! empty( $feature_roles ) && ! empty( array_intersect( $user_roles, $feature_roles ) ) );
942947
}
943948

0 commit comments

Comments
 (0)