settings = Settings::getInstance(); $this->cache = Cache::getInstance(); } /** * Settings page */ public function index() { $this->checkCapability(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { return $this->save(); } $settings = $this->settings->all(); $this->render('settings', [ 'settings' => $settings, 'current_page' => 'sodino-settings' ]); } /** * Save settings */ private function save() { $this->verifyNonce('sodino_settings_nonce', 'sodino_save_settings'); $settings = [ 'plugin_enabled' => isset($_POST['plugin_enabled']) ? 1 : 0, 'pricing_enabled' => isset($_POST['pricing_enabled']) ? 1 : 0, 'upsell_enabled' => isset($_POST['upsell_enabled']) ? 1 : 0, 'banner_enabled' => isset($_POST['banner_enabled']) ? 1 : 0, 'allow_multiple_rules' => isset($_POST['allow_multiple_rules']) ? 1 : 0, 'strategy' => sanitize_text_field($_POST['strategy'] ?? 'priority'), 'max_discount_percent' => max(0, min(100, floatval($_POST['max_discount_percent'] ?? 100))), 'min_product_price' => max(0, floatval($_POST['min_product_price'] ?? 0)), 'ab_testing_enabled' => isset($_POST['ab_testing_enabled']) ? 1 : 0, 'cart_pricing_enabled' => isset($_POST['cart_pricing_enabled']) ? 1 : 0, 'scheduled_campaigns_enabled' => isset($_POST['scheduled_campaigns_enabled']) ? 1 : 0, 'cache_enabled' => isset($_POST['cache_enabled']) ? 1 : 0, 'cache_duration' => max(60, intval($_POST['cache_duration'] ?? 3600)), 'debug_mode' => isset($_POST['debug_mode']) ? 1 : 0, ]; $this->settings->update($settings); // Clear cache when settings change $this->cache->clearAll(); $this->redirect( admin_url('admin.php?page=sodino-settings'), __('تنظیمات با موفقیت ذخیره شد.', 'sodino') ); } /** * Clear cache action */ public function clearCache() { $this->checkCapability(); if (!isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'clear_cache')) { wp_die(__('خطای امنیتی رخ داد.', 'sodino')); } $this->cache->clearAll(); $this->redirect( admin_url('admin.php?page=sodino-settings'), __('کش با موفقیت پاک شد.', 'sodino') ); } }