@@ -178,9 +178,7 @@ public function add_custom_settings_fields() {
178
178
protected function get_default_settings (): array {
179
179
$ shared_defaults = [
180
180
'status ' => '0 ' ,
181
- 'role_based_access ' => '1 ' ,
182
181
'roles ' => array_combine ( array_keys ( $ this ->roles ), array_keys ( $ this ->roles ) ),
183
- 'user_based_access ' => 'no ' ,
184
182
'users ' => [],
185
183
'user_based_opt_out ' => 'no ' ,
186
184
];
@@ -222,25 +220,13 @@ public function sanitize_settings( array $settings ): array {
222
220
$ new_settings ['status ' ] = $ settings ['status ' ] ?? $ current_settings ['status ' ];
223
221
$ new_settings ['provider ' ] = isset ( $ settings ['provider ' ] ) ? sanitize_text_field ( $ settings ['provider ' ] ) : $ current_settings ['provider ' ];
224
222
225
- if ( empty ( $ settings ['role_based_access ' ] ) || 1 !== (int ) $ settings ['role_based_access ' ] ) {
226
- $ new_settings ['role_based_access ' ] = 'no ' ;
227
- } else {
228
- $ new_settings ['role_based_access ' ] = '1 ' ;
229
- }
230
-
231
223
// Allowed roles.
232
224
if ( isset ( $ settings ['roles ' ] ) && is_array ( $ settings ['roles ' ] ) ) {
233
225
$ new_settings ['roles ' ] = array_map ( 'sanitize_text_field ' , $ settings ['roles ' ] );
234
226
} else {
235
227
$ new_settings ['roles ' ] = $ current_settings ['roles ' ];
236
228
}
237
229
238
- if ( empty ( $ settings ['user_based_access ' ] ) || 1 !== (int ) $ settings ['user_based_access ' ] ) {
239
- $ new_settings ['user_based_access ' ] = 'no ' ;
240
- } else {
241
- $ new_settings ['user_based_access ' ] = '1 ' ;
242
- }
243
-
244
230
// Allowed users.
245
231
if ( isset ( $ settings ['users ' ] ) && ! empty ( $ settings ['users ' ] ) ) {
246
232
if ( is_array ( $ settings ['users ' ] ) ) {
@@ -448,27 +434,6 @@ public function reset_settings() {
448
434
protected function add_access_control_fields () {
449
435
$ settings = $ this ->get_settings ();
450
436
451
- add_settings_field (
452
- 'role_based_access ' ,
453
- esc_html__ ( 'Enable role-based access ' , 'classifai ' ),
454
- [ $ this , 'render_input ' ],
455
- $ this ->get_option_name (),
456
- $ this ->get_option_name () . '_section ' ,
457
- [
458
- 'label_for ' => 'role_based_access ' ,
459
- 'input_type ' => 'checkbox ' ,
460
- 'default_value ' => $ settings ['role_based_access ' ],
461
- 'description ' => __ ( 'Enables ability to select which roles can access this feature. ' , 'classifai ' ),
462
- 'class ' => 'classifai-role-based-access ' ,
463
- ]
464
- );
465
-
466
- // Add hidden class if role-based access is disabled.
467
- $ class = 'allowed_roles_row ' ;
468
- if ( ! isset ( $ settings ['role_based_access ' ] ) || '1 ' !== $ settings ['role_based_access ' ] ) {
469
- $ class .= ' hidden ' ;
470
- }
471
-
472
437
add_settings_field (
473
438
'roles ' ,
474
439
esc_html__ ( 'Allowed roles ' , 'classifai ' ),
@@ -480,31 +445,10 @@ protected function add_access_control_fields() {
480
445
'options ' => $ this ->roles ,
481
446
'default_values ' => $ settings ['roles ' ],
482
447
'description ' => __ ( 'Choose which roles are allowed to access this feature. ' , 'classifai ' ),
483
- 'class ' => $ class ,
448
+ 'class ' => ' allowed_roles_row ' ,
484
449
]
485
450
);
486
451
487
- add_settings_field (
488
- 'user_based_access ' ,
489
- esc_html__ ( 'Enable user-based access ' , 'classifai ' ),
490
- [ $ this , 'render_input ' ],
491
- $ this ->get_option_name (),
492
- $ this ->get_option_name () . '_section ' ,
493
- [
494
- 'label_for ' => 'user_based_access ' ,
495
- 'input_type ' => 'checkbox ' ,
496
- 'default_value ' => $ settings ['user_based_access ' ],
497
- 'description ' => __ ( 'Enables ability to select which users can access this feature. ' , 'classifai ' ),
498
- 'class ' => 'classifai-user-based-access ' ,
499
- ]
500
- );
501
-
502
- // Add hidden class if user-based access is disabled.
503
- $ users_class = 'allowed_users_row ' ;
504
- if ( ! isset ( $ settings ['user_based_access ' ] ) || '1 ' !== $ settings ['user_based_access ' ] ) {
505
- $ users_class .= ' hidden ' ;
506
- }
507
-
508
452
add_settings_field (
509
453
'users ' ,
510
454
esc_html__ ( 'Allowed users ' , 'classifai ' ),
@@ -515,7 +459,7 @@ protected function add_access_control_fields() {
515
459
'label_for ' => 'users ' ,
516
460
'default_value ' => $ settings ['users ' ],
517
461
'description ' => __ ( 'Users who have access to this feature. ' , 'classifai ' ),
518
- 'class ' => $ users_class ,
462
+ 'class ' => ' allowed_users_row ' ,
519
463
]
520
464
);
521
465
@@ -930,26 +874,22 @@ public function has_access(): bool {
930
874
$ feature_roles = $ settings ['roles ' ] ?? [];
931
875
$ feature_users = array_map ( 'absint ' , $ settings ['users ' ] ?? [] );
932
876
933
- $ role_based_access_enabled = isset ( $ settings ['role_based_access ' ] ) && 1 === (int ) $ settings ['role_based_access ' ];
934
- $ user_based_access_enabled = isset ( $ settings ['user_based_access ' ] ) && 1 === (int ) $ settings ['user_based_access ' ];
935
877
$ user_based_opt_out_enabled = isset ( $ settings ['user_based_opt_out ' ] ) && 1 === (int ) $ settings ['user_based_opt_out ' ];
936
878
937
879
/*
938
- * Checks if Role-based access is enabled and user role has access to the feature.
880
+ * Checks if the user role has access to the feature.
939
881
*/
940
- 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
-
946
- $ access = ( ! empty ( $ feature_roles ) && ! empty ( array_intersect ( $ user_roles , $ feature_roles ) ) );
882
+ // For super admins that don't have a specific role on a site, treat them as admins.
883
+ if ( is_multisite () && is_super_admin ( $ user_id ) && empty ( $ user_roles ) ) {
884
+ $ user_roles = [ 'administrator ' ];
947
885
}
948
886
887
+ $ access = ( ! empty ( $ feature_roles ) && ! empty ( array_intersect ( $ user_roles , $ feature_roles ) ) );
888
+
949
889
/*
950
- * Checks if User-based access is enabled and user has access to the feature.
890
+ * Checks if has access to the feature.
951
891
*/
952
- if ( ! $ access && $ user_based_access_enabled ) {
892
+ if ( ! $ access ) {
953
893
$ access = ( ! empty ( $ feature_users ) && ! empty ( in_array ( $ user_id , $ feature_users , true ) ) );
954
894
}
955
895
@@ -1160,9 +1100,7 @@ function ( $role ) {
1160
1100
$ common_debug_info = [
1161
1101
__ ( 'Authenticated ' , 'classifai ' ) => self ::get_debug_value_text ( $ this ->is_configured () ),
1162
1102
__ ( 'Status ' , 'classifai ' ) => self ::get_debug_value_text ( $ feature_settings ['status ' ], 1 ),
1163
- __ ( 'Role-based access ' , 'classifai ' ) => self ::get_debug_value_text ( $ feature_settings ['role_based_access ' ], 1 ),
1164
1103
__ ( 'Allowed roles (titles) ' , 'classifai ' ) => implode ( ', ' , $ roles ?? [] ),
1165
- __ ( 'User-based access ' , 'classifai ' ) => self ::get_debug_value_text ( $ feature_settings ['user_based_access ' ], 1 ),
1166
1104
__ ( 'Allowed users (titles) ' , 'classifai ' ) => implode ( ', ' , $ feature_settings ['users ' ] ?? [] ),
1167
1105
__ ( 'User based opt-out ' , 'classifai ' ) => self ::get_debug_value_text ( $ feature_settings ['user_based_opt_out ' ], 1 ),
1168
1106
__ ( 'Provider ' , 'classifai ' ) => $ feature_settings ['provider ' ],
0 commit comments