fix: Access control settings improvements - Revert role checkboxes layout to previous styling - Fix settings saving functionality with proper result checking - Update error message to 'Error Saving' - Only load functionality when settings are enabled - Use empty arrays as defaults for role settings
This commit is contained in:
@ -814,13 +814,6 @@ input:checked + .wp-toggle-slider:before {
|
|||||||
.wp-allstars-role-checkbox span {
|
.wp-allstars-role-checkbox span {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust label padding on mobile */
|
|
||||||
.wp-setting-left label,
|
|
||||||
.wp-allstars-toggle-left label,
|
|
||||||
.wp-allstars-setting-row label {
|
|
||||||
padding-right: 70px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes fadeIn {
|
@keyframes fadeIn {
|
||||||
|
@ -183,18 +183,18 @@ class WP_Allstars_Access_Manager {
|
|||||||
// Handle different setting types
|
// Handle different setting types
|
||||||
switch ($setting) {
|
switch ($setting) {
|
||||||
case 'wp_allstars_hide_admin_bar':
|
case 'wp_allstars_hide_admin_bar':
|
||||||
update_option('wp_allstars_hide_admin_bar_roles', $value ? array('guest', 'subscriber', 'customer') : array());
|
$result = update_option('wp_allstars_hide_admin_bar_roles', $value ? array('guest', 'subscriber', 'customer') : array());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'wp_allstars_restrict_dashboard':
|
case 'wp_allstars_restrict_dashboard':
|
||||||
update_option('wp_allstars_restrict_dashboard_roles', $value ? array('guest', 'subscriber', 'customer') : array());
|
$result = update_option('wp_allstars_restrict_dashboard_roles', $value ? array('guest', 'subscriber', 'customer') : array());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'wp_allstars_hide_admin_bar_roles':
|
case 'wp_allstars_hide_admin_bar_roles':
|
||||||
case 'wp_allstars_restrict_dashboard_roles':
|
case 'wp_allstars_restrict_dashboard_roles':
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$value = array_map('sanitize_text_field', $value);
|
$value = array_map('sanitize_text_field', $value);
|
||||||
update_option($setting, $value);
|
$result = update_option($setting, $value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -202,13 +202,22 @@ class WP_Allstars_Access_Manager {
|
|||||||
wp_send_json_error('Invalid setting name');
|
wp_send_json_error('Invalid setting name');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
wp_send_json_success();
|
wp_send_json_success();
|
||||||
|
} else {
|
||||||
|
wp_send_json_error('Failed to save setting');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up access control hooks
|
* Set up access control hooks
|
||||||
*/
|
*/
|
||||||
public static function setup_access_control() {
|
public static function setup_access_control() {
|
||||||
|
// Only run if the feature is enabled
|
||||||
|
if (!get_option('wp_allstars_hide_admin_bar_roles') && !get_option('wp_allstars_restrict_dashboard_roles')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get current user
|
// Get current user
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
if (!$user->exists()) {
|
if (!$user->exists()) {
|
||||||
@ -219,8 +228,8 @@ class WP_Allstars_Access_Manager {
|
|||||||
$user_roles = $user->roles;
|
$user_roles = $user->roles;
|
||||||
|
|
||||||
// Get restricted roles from settings
|
// Get restricted roles from settings
|
||||||
$hide_admin_bar_roles = get_option('wp_allstars_hide_admin_bar_roles', array('guest', 'subscriber', 'customer'));
|
$hide_admin_bar_roles = get_option('wp_allstars_hide_admin_bar_roles', array());
|
||||||
$restrict_dashboard_roles = get_option('wp_allstars_restrict_dashboard_roles', array('guest', 'subscriber', 'customer'));
|
$restrict_dashboard_roles = get_option('wp_allstars_restrict_dashboard_roles', array());
|
||||||
|
|
||||||
// Check if user's role is in restricted roles
|
// Check if user's role is in restricted roles
|
||||||
$should_hide_admin_bar = array_intersect($user_roles, $hide_admin_bar_roles);
|
$should_hide_admin_bar = array_intersect($user_roles, $hide_admin_bar_roles);
|
||||||
|
Reference in New Issue
Block a user