From b33a8aceaeb4575677c9e5e06cdbb3b308fdb758 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Sun, 4 Feb 2024 20:46:29 -0700 Subject: [PATCH 1/2] When checking to see if a user has access based on their role, if they have no roles set on a site but they are a super admin, set their role to administrator --- includes/Classifai/Features/Feature.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 7f11af94e..2fad3ccad 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -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 ) ) ); } From e8c37e745f895e5830d9ca65f3eeb4dbcbd6dac5 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Sun, 4 Feb 2024 20:47:11 -0700 Subject: [PATCH 2/2] When checking to see if a user has access to opt out of a feature, if they have no role set but are a super admin, set their role to administrator --- includes/Classifai/Admin/UserProfile.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/includes/Classifai/Admin/UserProfile.php b/includes/Classifai/Admin/UserProfile.php index 4982f2862..7131fc1ac 100644 --- a/includes/Classifai/Admin/UserProfile.php +++ b/includes/Classifai/Admin/UserProfile.php @@ -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.