PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
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/Controllers/Settings/UpdateSettingController.php +18 -6 0.8.2 → 1.5.1 View file →
@@ -6,13 +6,8 @@
6 6 */
7 7
8 8 namespace IvyForms\Controllers\Settings;
9 9
10 -// phpcs:disable PSR1.Files.SideEffects
11 -if (!defined('ABSPATH')) {
12 - exit; // Exit if accessed directly
13 -}
14 -
15 10 use IvyForms\Common\Exceptions\ForbiddenException;
16 11 use IvyForms\Common\Exceptions\InvalidArgumentException;
17 12 use IvyForms\Common\Sanitizer\Sanitizer;
18 13 use IvyForms\Controllers\Controller;
@@ -17,8 +12,9 @@
17 12 use IvyForms\Common\Sanitizer\Sanitizer;
18 13 use IvyForms\Controllers\Controller;
19 14 use IvyForms\Services\Settings\SettingsService;
20 15 use IvyForms\Services\Translations\BackendStrings;
16 +use IvyForms\Services\Usage\UsageTrackingService;
21 17 use WP_REST_Request;
22 18 use WP_REST_Response;
23 19
24 20 /**
@@ -28,13 +24,16 @@
28 24 */
29 25 class UpdateSettingController extends Controller
30 26 {
31 27 private SettingsService $settingsService;
28 + private UsageTrackingService $usageTrackingService;
32 29
33 30 public function __construct(
34 - SettingsService $settingsService
31 + SettingsService $settingsService,
32 + UsageTrackingService $usageTrackingService
35 33 ) {
36 34 $this->settingsService = $settingsService;
35 + $this->usageTrackingService = $usageTrackingService;
37 36 }
38 37
39 38 /**
40 39 * @param WP_REST_Request $data
@@ -63,8 +62,21 @@
63 62 if (empty($settingsCategory) || empty($settingsOption)) {
64 63 throw new InvalidArgumentException(
65 64 BackendStrings::getSettingsStrings()['settings_category_or_option_missing']
66 65 );
66 + }
67 +
68 + if ($settingsCategory === 'general' && $settingsOption === 'usageTrackingEnabled') {
69 + $updatedSettings = $this->usageTrackingService->updateSettings([
70 + 'usageTrackingEnabled' => (bool) $settingsValue,
71 + ]);
72 +
73 + return new WP_REST_Response([
74 + 'message' => BackendStrings::getSettingsStrings()['settings_option_updated'],
75 + 'data' => [
76 + 'value' => $updatedSettings['usageTrackingEnabled'],
77 + ],
78 + ], 200);
67 79 }
68 80
69 81 // Update the setting
70 82 $this->settingsService->setSetting($settingsCategory, $settingsOption, $settingsValue);