Skip to content

Commit

Permalink
Merge pull request #689 from 10up/fix/658
Browse files Browse the repository at this point in the history
For super admins with no role set, treat them as administrators
  • Loading branch information
iamdharmesh authored Feb 5, 2024
2 parents 0180001 + e8c37e7 commit f5e9c60
Show file tree
Hide file tree
Showing 2 changed files with 18 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
5 changes: 5 additions & 0 deletions includes/Classifai/Features/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,11 @@ public function has_access(): bool {
* Checks if Role-based access is enabled and user role has access to the feature.
*/
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' ];
}

$access = ( ! empty( $feature_roles ) && ! empty( array_intersect( $user_roles, $feature_roles ) ) );
}

Expand Down

0 comments on commit f5e9c60

Please sign in to comment.