isset($_POST['atvm_hide_toolbar_logo']) ? 'on' : 'off', 'atvm_disable_frontend' => isset($_POST['atvm_disable_frontend']) ? 'on' : 'off', 'atvm_hide_all_users' => isset($_POST['atvm_hide_all_users']) ? 'on' : 'off', 'atvm_hide_all_guests' => isset($_POST['atvm_hide_all_guests']) ? 'on' : 'off', 'atvm_adminbar_position' => sanitize_text_field($_POST['atvm_adminbar_position']), 'atvm_bg_type' => sanitize_text_field($_POST['atvm_bg_type']), 'atvm_bg_color' => sanitize_text_field($_POST['atvm_bg_color']), 'atvm_text_color' => sanitize_text_field($_POST['atvm_text_color']), 'atvm_dropdown_style' => sanitize_text_field($_POST['atvm_dropdown_style']), 'atvm_new_button_color' => sanitize_text_field($_POST['atvm_new_button_color']), 'atvm_custom_logo' => esc_url_raw($_POST['atvm_custom_logo']), 'atvm_custom_logo_url' => esc_url_raw($_POST['atvm_custom_logo_url']), 'atvm_auto_save' => isset($_POST['atvm_auto_save']) ? 'on' : 'off' ); foreach ($settings as $key => $value) { update_option($key, $value); } wp_send_json_success(__('Settings saved automatically.', 'akashahmed-toolbar-visibility')); } // Handle settings reset add_action('wp_ajax_atvm_reset_settings', 'atvm_reset_settings'); function atvm_reset_settings() { check_ajax_referer('atvm_nonce', 'security'); if (!current_user_can('manage_options')) { wp_send_json_error(__('You do not have sufficient permissions.', 'akashahmed-toolbar-visibility')); } // Delete all plugin options $roles = ['subscriber', 'contributor', 'author', 'editor', 'administrator']; foreach ($roles as $role) { delete_option("atvm_hide_toolbar_{$role}"); } $options = array( 'atvm_hide_toolbar_logo', 'atvm_disable_frontend', 'atvm_hide_all_users', 'atvm_hide_all_guests', 'atvm_adminbar_position', 'atvm_bg_type', 'atvm_bg_color', 'atvm_text_color', 'atvm_dropdown_style', 'atvm_new_button_color', 'atvm_custom_logo', 'atvm_custom_logo_url', 'atvm_auto_save', 'atvm_admin_bar_customizations' ); foreach ($options as $option) { delete_option($option); } require_once ATVM_INCLUDES . '/class-install.php'; // Recreate defaults ATVM_Install::activate(); wp_send_json_success(__('All settings have been reset to defaults.', 'akashahmed-toolbar-visibility')); } // Handle settings export add_action('wp_ajax_atvm_export_settings', 'atvm_export_settings'); // function atvm_export_settings() { // check_ajax_referer('atvm_nonce', 'security'); // if (!current_user_can('manage_options')) { // wp_die(__('You do not have sufficient permissions.', 'akashahmed-toolbar-visibility')); // } // $settings = array(); // // Get all role settings // $roles = ['subscriber', 'contributor', 'author', 'editor', 'administrator']; // foreach ($roles as $role) { // $settings["atvm_hide_toolbar_{$role}"] = get_option("atvm_hide_toolbar_{$role}", 'off'); // } // // Get other settings // $options = array( // 'atvm_hide_toolbar_logo', // 'atvm_disable_frontend', // 'atvm_hide_all_users', // 'atvm_hide_all_guests', // 'atvm_adminbar_position', // 'atvm_bg_type', // 'atvm_bg_color', // 'atvm_text_color', // 'atvm_dropdown_style', // 'atvm_new_button_color', // 'atvm_custom_logo', // 'atvm_custom_logo_url', // 'atvm_auto_save', // 'atvm_admin_bar_customizations' // ); // foreach ($options as $option) { // $settings[$option] = get_option($option); // } // // Send as JSON file // header('Content-disposition: attachment; filename=akashahmed-toolbar-visibility-settings-' . date('Y-m-d') . '.json'); // header('Content-type: application/json'); // echo json_encode($settings); // exit; // } function atvm_export_settings() { check_ajax_referer('atvm_nonce', 'security'); if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions.', 'akashahmed-toolbar-visibility')); } $settings = array(); // Get all role settings $roles = ['subscriber', 'contributor', 'author', 'editor', 'administrator']; foreach ($roles as $role) { $settings["atvm_hide_toolbar_{$role}"] = get_option("atvm_hide_toolbar_{$role}", 'off'); } // Get other settings $options = array( 'atvm_hide_toolbar_logo', 'atvm_disable_frontend', 'atvm_hide_all_users', 'atvm_hide_all_guests', 'atvm_adminbar_position', 'atvm_bg_type', 'atvm_bg_color', 'atvm_text_color', 'atvm_dropdown_style', 'atvm_new_button_color', 'atvm_custom_logo', 'atvm_custom_logo_url', 'atvm_auto_save' ); foreach ($options as $option) { $settings[$option] = get_option($option); } // Send as JSON file header('Content-Type: application/json'); header('Content-Disposition: attachment; filename=akashahmed-toolbar-visibility-settings-' . date('Y-m-d') . '.json'); header('Pragma: no-cache'); header('Expires: 0'); echo json_encode($settings); exit; } // Handle settings import add_action('wp_ajax_atvm_import_settings', 'atvm_import_settings'); function atvm_import_settings() { check_ajax_referer('atvm_nonce', 'security'); if (!current_user_can('manage_options')) { wp_send_json_error(__('You do not have sufficient permissions.', 'akashahmed-toolbar-visibility')); } if (empty($_FILES['settings_file']['tmp_name'])) { wp_send_json_error(__('No file uploaded.', 'akashahmed-toolbar-visibility')); } $file_content = file_get_contents($_FILES['settings_file']['tmp_name']); $settings = json_decode($file_content, true); if (json_last_error() !== JSON_ERROR_NONE || !is_array($settings)) { wp_send_json_error(__('Invalid settings file.', 'akashahmed-toolbar-visibility')); } // Import all settings foreach ($settings as $key => $value) { update_option($key, $value); } wp_send_json_success(__('Settings imported successfully.', 'akashahmed-toolbar-visibility')); } // Handle logo upload add_action('wp_ajax_atvm_upload_logo', 'atvm_upload_logo'); function atvm_upload_logo() { check_ajax_referer('atvm_nonce', 'security'); if (!current_user_can('upload_files')) { wp_send_json_error(__('You do not have permission to upload files.', 'akashahmed-toolbar-visibility')); } if (!function_exists('wp_handle_upload')) { require_once(ABSPATH . 'wp-admin/includes/file.php'); } $uploadedfile = $_FILES['atvm_logo_upload']; $upload_overrides = array('test_form' => false); $movefile = wp_handle_upload($uploadedfile, $upload_overrides); if ($movefile && !isset($movefile['error'])) { update_option('atvm_custom_logo', $movefile['url']); wp_send_json_success(array( 'url' => $movefile['url'], 'message' => __('Logo uploaded successfully.', 'akashahmed-toolbar-visibility') )); } else { wp_send_json_error($movefile['error']); } }