'', 'description' => '', 'code' => '', 'url' => '', 'img' => '', ); } } /* 2) HANDLE FORM SUBMISSION -------------------------------------------------------- */ if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset($_POST['adventi_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['adventi_nonce'])), 'adventi_save_gifts') ) { /* ---- Save Days Count ---- */ if (isset($_POST['adventi_days_count'])) { $count = absint($_POST['adventi_days_count']); update_option('adventi_days_count', $count); $days = $count; } else { $days = 12; } /* Save palette -------------------------------------------------------- */ if (isset($_POST['adventi_color_scheme'])) { $clean_palette = sanitize_text_field(wp_unslash($_POST['adventi_color_scheme'])); update_option('adventi_color_scheme', $clean_palette); $palette = $clean_palette; } /* Save colors -------------------------------------------------------- */ $color_fields = array( 'adventi_locked_color', 'adventi_unlocked_color', 'adventi_form_button_color', ); foreach ($color_fields as $field) { if (isset($_POST[$field])) { $hex = sanitize_hex_color(wp_unslash($_POST[$field])); if ($hex) { update_option($field, $hex); } } } /* Save texts -------------------------------------------------------- */ $text_fields = array( 'adventi_main_title', 'adventi_invitation_text', 'adventi_submit_text', 'adventi_day_prefix', 'adventi_tomorrow_message', 'adventi_future_msg', 'adventi_download_text', ); foreach ($text_fields as $field) { if (isset($_POST[$field])) { $value = sanitize_text_field(wp_unslash($_POST[$field])); update_option($field, $value); } } /* Save start date -------------------------------------------------------- */ if (isset($_POST['adventi_start_date'])) { $clean_date = sanitize_text_field(wp_unslash($_POST['adventi_start_date'])); update_option('adventi_start_date', $clean_date); $start = $clean_date; } /* Save gifts (title, description, code, url, img) -------------------------------------------------------- */ $cleaned = array(); if (isset($_POST['adventi_gifts']) && is_array($_POST['adventi_gifts'])) { require_once ABSPATH . 'wp-admin/includes/file.php'; $existing = get_option('adventi_gifts_settings', array()); foreach ($_POST['adventi_gifts'] as $day => $gift) { $day = absint($day); $cleaned[$day] = array( 'title' => sanitize_text_field($gift['title'] ?? ''), 'description' => sanitize_text_field($gift['description'] ?? ''), 'code' => sanitize_text_field($gift['code'] ?? ''), 'url' => esc_url_raw($gift['url'] ?? ''), ); } } update_option('adventi_gifts_settings', $cleaned); $gifts = $cleaned; /* SUCCESS NOTICE -------------------------------------------------------- */ add_action( 'admin_notices', function () { echo '

' . esc_html__('Settings saved successfully.', 'adventi') . '

'; } ); } /* 3) LOAD VIEW TEMPLATE -------------------------------------------------------- */ $view_path = ADVENTI_PLUGIN_DIR . 'admin/views/settings-view.php'; if (file_exists($view_path)) { include $view_path; } }