← All changes
|
backend/src/Controllers/Settings/GetAllSettingsController.php
+75
-14
0.3.1
→
1.5
View file →
| @@ -1,23 +1,20 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * @copyright © TMS-Plugins. All rights reserved. | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | 5 | * @licence See COPYING.md for license details. |
| 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\Sanitizer\Sanitizer; |
| 17 | 12 | use IvyForms\Controllers\Controller; |
| 13 | +use IvyForms\Infrastructure\WP\MCP\McpFeatureGate; | |
| 18 | 14 | use IvyForms\Services\Settings\SettingsService; |
| 19 | 15 | use IvyForms\Services\Translations\BackendStrings; |
| 16 | +use IvyForms\Services\Usage\UsageTrackingService; | |
| 20 | 17 | use WP_REST_Request; |
| 21 | 18 | use WP_REST_Response; |
| 22 | 19 | |
| 23 | 20 | /** |
| @@ -27,13 +24,16 @@ | ||
| 27 | 24 | */ |
| 28 | 25 | class GetAllSettingsController extends Controller |
| 29 | 26 | { |
| 30 | 27 | private SettingsService $settingsService; |
| 28 | + private UsageTrackingService $usageTrackingService; | |
| 31 | 29 | |
| 32 | 30 | public function __construct( |
| 33 | - SettingsService $settingsService | |
| 31 | + SettingsService $settingsService, | |
| 32 | + UsageTrackingService $usageTrackingService | |
| 34 | 33 | ) { |
| 35 | 34 | $this->settingsService = $settingsService; |
| 35 | + $this->usageTrackingService = $usageTrackingService; | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Get all settings organized by category |
| @@ -55,11 +55,10 @@ | ||
| 55 | 55 | // Organize settings structure for frontend (prepare for future extensions) |
| 56 | 56 | $organizedSettings = [ |
| 57 | 57 | 'security' => [ |
| 58 | 58 | 'recaptcha' => $allSettings['security']['recaptcha'] ?? null, |
| 59 | - // Future extensions can be added here: | |
| 60 | - // 'hcaptcha' => $allSettings['security']['hcaptcha'] ?? null, | |
| 61 | - // 'turnstile' => $allSettings['security']['turnstile'] ?? null, | |
| 59 | + 'turnstile' => $allSettings['security']['turnstile'] ?? null, | |
| 60 | + 'hcaptcha' => $allSettings['security']['hcaptcha'] ?? null, | |
| 62 | 61 | |
| 63 | 62 | // Example: If you wanted to include security status info, you could inject SecurityService: |
| 64 | 63 | // 'status' => [ |
| 65 | 64 | // 'activeCaptchaProvider' => $this->securityService->getActiveCaptchaProvider(), |
| @@ -66,17 +65,79 @@ | ||
| 66 | 65 | // 'isCaptchaConfigured' => $this->securityService->isCaptchaConfigured(), |
| 67 | 66 | // ] |
| 68 | 67 | ], |
| 69 | 68 | 'general' => [ |
| 70 | - // Future general settings can be added here: | |
| 71 | - // 'site_settings' => $allSettings['general']['site_settings'] ?? null, | |
| 72 | - // 'form_defaults' => $allSettings['general']['form_defaults'] ?? null, | |
| 69 | + 'wcagBackend' => $allSettings['general']['wcagBackend'] ?? false, | |
| 70 | + 'mcp_enabled' => McpFeatureGate::coerceStoredEnabled( | |
| 71 | + $allSettings['general']['mcp_enabled'] ?? true | |
| 72 | + ), | |
| 73 | + 'favoriteTemplates' => $allSettings['general']['favoriteTemplates'] ?? [], | |
| 74 | + 'delete_on_uninstall' => $allSettings['general']['delete_on_uninstall'] ?? false, | |
| 75 | + 'usageTrackingEnabled' => $this->usageTrackingService->isSettingEnabled(), | |
| 73 | 76 | ], |
| 74 | - // Future categories can be added here | |
| 77 | + 'integrations' => [ | |
| 78 | + 'wpdatatables' => array_merge( | |
| 79 | + $allSettings['integrations']['wpdatatables'] ?? ['enabled' => false], | |
| 80 | + [ | |
| 81 | + 'connected' => class_exists('WPDataTable') || defined('WDT_ROOT_PATH') | |
| 82 | + ] | |
| 83 | + ), | |
| 84 | + 'ameliabooking' => array_merge( | |
| 85 | + $allSettings['integrations']['ameliabooking'] ?? ['enabled' => false], | |
| 86 | + [ | |
| 87 | + 'connected' => class_exists('AmeliaBooking\Plugin') || defined('AMELIA_PATH') | |
| 88 | + ] | |
| 89 | + ), | |
| 90 | + 'square' => array_merge( | |
| 91 | + $allSettings['integrations']['square'] ?? ['enabled' => false], | |
| 92 | + [ | |
| 93 | + 'connected' => ! empty($allSettings['payment']['square']['connected']), | |
| 94 | + ] | |
| 95 | + ), | |
| 96 | + ], | |
| 97 | + 'payment' => [ | |
| 98 | + 'square' => self::sanitizeSquareSettingsForFrontend( | |
| 99 | + is_array($allSettings['payment']['square'] ?? null) | |
| 100 | + ? $allSettings['payment']['square'] | |
| 101 | + : [] | |
| 102 | + ), | |
| 103 | + ], | |
| 75 | 104 | ]; |
| 76 | 105 | |
| 106 | + /** | |
| 107 | + * Filter to allow Pro plugin to add additional settings data | |
| 108 | + * | |
| 109 | + * @param array $organizedSettings The organized settings array | |
| 110 | + * @param array $allSettings The raw settings from database | |
| 111 | + * | |
| 112 | + * @since 1.0.0 | |
| 113 | + */ | |
| 114 | + $organizedSettings = apply_filters('ivyforms/global/settings/get_all', $organizedSettings, $allSettings); | |
| 115 | + | |
| 77 | 116 | return new WP_REST_Response([ |
| 78 | 117 | 'message' => BackendStrings::getSettingsStrings()['all_settings_retrieved'], |
| 79 | 118 | 'data' => $organizedSettings |
| 80 | 119 | ], 200); |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * @param array<string, mixed> $squareSettings | |
| 124 | + * @return array<string, mixed> | |
| 125 | + */ | |
| 126 | + private static function sanitizeSquareSettingsForFrontend(array $squareSettings): array | |
| 127 | + { | |
| 128 | + $defaults = [ | |
| 129 | + 'connected' => false, | |
| 130 | + 'merchantId' => '', | |
| 131 | + 'merchantName' => '', | |
| 132 | + 'locationId' => '', | |
| 133 | + 'locationName' => '', | |
| 134 | + 'currency' => '', | |
| 135 | + 'disconnectedByWebhook' => false, | |
| 136 | + ]; | |
| 137 | + | |
| 138 | + $merged = array_merge($defaults, $squareSettings); | |
| 139 | + unset($merged['accessToken'], $merged['refreshToken']); | |
| 140 | + | |
| 141 | + return $merged; | |
| 81 | 142 | } |
| 82 | 143 | } |