PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
← All changes | backend/src/Services/Settings/SettingsService.php +55 -17 1.0 → 1.5 View file →
@@ -32,9 +32,39 @@
32 32 */
33 33 public function __construct()
34 34 {
35 35 $this->settingsCache = json_decode(get_option('ivyforms_settings'), true);
36 + if (!is_array($this->settingsCache)) {
37 + $this->settingsCache = [];
38 + }
36 39
40 + $this->refreshWordPressSettingsCache();
41 + }
42 +
43 + /**
44 + * @return array<string, mixed>
45 + */
46 + private function readStoredSettings(): array
47 + {
48 + $stored = json_decode((string) get_option('ivyforms_settings'), true);
49 +
50 + return is_array($stored) ? $stored : [];
51 + }
52 +
53 + /**
54 + * @param array<string, mixed> $stored
55 + */
56 + private function writeStoredSettings(array $stored): void
57 + {
58 + update_option('ivyforms_settings', json_encode($stored));
59 + }
60 +
61 + private function refreshWordPressSettingsCache(): void
62 + {
63 + if (!isset($this->settingsCache['wordpress']) || !is_array($this->settingsCache['wordpress'])) {
64 + $this->settingsCache['wordpress'] = [];
65 + }
66 +
37 67 foreach (self::$wpSettings as $setting => $wpSetting) {
38 68 $this->settingsCache['wordpress'][$setting] = get_option($wpSetting);
39 69 }
40 70 }
@@ -114,15 +144,25 @@
114 144 * @return void
115 145 */
116 146 public function setSetting(string $settingCategoryKey, string $settingKey, $settingValue)
117 147 {
118 - $this->settingsCache[$settingCategoryKey][$settingKey] = $settingValue;
148 + if ($settingCategoryKey === 'integrations' && is_array($settingValue)) {
149 + $existing = $this->getSetting($settingCategoryKey, $settingKey);
150 + if (is_array($existing)) {
151 + $settingValue = array_merge($existing, $settingValue);
152 + }
153 + }
119 154
120 - $settingsCopy = $this->settingsCache;
155 + $stored = $this->readStoredSettings();
121 156
122 - unset($settingsCopy['wordpress']);
157 + if (!isset($stored[$settingCategoryKey]) || !is_array($stored[$settingCategoryKey])) {
158 + $stored[$settingCategoryKey] = [];
159 + }
123 160
124 - update_option('ivyforms_settings', json_encode($settingsCopy));
161 + $stored[$settingCategoryKey][$settingKey] = $settingValue;
162 + $this->settingsCache = $stored;
163 + $this->refreshWordPressSettingsCache();
164 + $this->writeStoredSettings($stored);
125 165 }
126 166
127 167 /**
128 168 * @param string $settingCategoryKey
@@ -131,15 +171,13 @@
131 171 * @return void
132 172 */
133 173 public function setCategorySettings(string $settingCategoryKey, $settingValue)
134 174 {
135 - $this->settingsCache[$settingCategoryKey] = $settingValue;
136 -
137 - $settingsCopy = $this->settingsCache;
138 -
139 - unset($settingsCopy['wordpress']);
140 -
141 - update_option('ivyforms_settings', json_encode($settingsCopy));
175 + $stored = $this->readStoredSettings();
176 + $stored[$settingCategoryKey] = $settingValue;
177 + $this->settingsCache = $stored;
178 + $this->refreshWordPressSettingsCache();
179 + $this->writeStoredSettings($stored);
142 180 }
143 181
144 182 /**
145 183 * Get all settings
@@ -149,15 +187,15 @@
149 187 *
150 188 */
151 189 public function setAllSettings(array $settings): void
152 190 {
191 + $stored = $this->readStoredSettings();
192 +
153 193 foreach ($settings as $settingCategoryKey => $settingValues) {
154 - $this->settingsCache[$settingCategoryKey] = $settingValues;
194 + $stored[$settingCategoryKey] = $settingValues;
155 195 }
156 196
157 - $settingsCopy = $this->settingsCache;
158 -
159 - unset($settingsCopy['wordpress']);
160 -
161 - update_option('ivyforms_settings', json_encode($settingsCopy));
197 + $this->settingsCache = $stored;
198 + $this->refreshWordPressSettingsCache();
199 + $this->writeStoredSettings($stored);
162 200 }
163 201 }