| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @copyright © Melograno Venture Studio. All rights reserved. |
| 5 |
* @licence See COPYING.md for license details. |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace IvyForms\Controllers\Settings; |
| 9 |
|
| 10 |
// phpcs:disable PSR1.Files.SideEffects |
| 11 |
if (!defined('ABSPATH')) { |
| 12 |
exit; // Exit if accessed directly |
| 13 |
} |
| 14 |
|
| 15 |
use IvyForms\Common\Exceptions\ForbiddenException; |
| 16 |
use IvyForms\Common\Sanitizer\Sanitizer; |
| 17 |
use IvyForms\Controllers\Controller; |
| 18 |
use IvyForms\Services\Settings\SettingsService; |
| 19 |
use IvyForms\Services\Translations\BackendStrings; |
| 20 |
use WP_REST_Request; |
| 21 |
use WP_REST_Response; |
| 22 |
|
| 23 |
/** |
| 24 |
* Class GetAllSettingsController |
| 25 |
* |
| 26 |
* @package IvyForms\Controllers\Settings |
| 27 |
*/ |
| 28 |
class GetAllSettingsController extends Controller |
| 29 |
{ |
| 30 |
private SettingsService $settingsService; |
| 31 |
|
| 32 |
public function __construct( |
| 33 |
SettingsService $settingsService |
| 34 |
) { |
| 35 |
$this->settingsService = $settingsService; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Get all settings organized by category |
| 40 |
* |
| 41 |
* @param WP_REST_Request $data |
| 42 |
* |
| 43 |
* @return WP_REST_Response |
| 44 |
* |
| 45 |
* @throws ForbiddenException |
| 46 |
*/ |
| 47 |
public function handle(WP_REST_Request $data): WP_REST_Response |
| 48 |
{ |
| 49 |
// Verify the nonce |
| 50 |
Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); |
| 51 |
|
| 52 |
// Get all settings from the service |
| 53 |
$allSettings = $this->settingsService->getAllSettings(); |
| 54 |
|
| 55 |
// Organize settings structure for frontend (prepare for future extensions) |
| 56 |
$organizedSettings = [ |
| 57 |
'security' => [ |
| 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, |
| 62 |
|
| 63 |
// Example: If you wanted to include security status info, you could inject SecurityService: |
| 64 |
// 'status' => [ |
| 65 |
// 'activeCaptchaProvider' => $this->securityService->getActiveCaptchaProvider(), |
| 66 |
// 'isCaptchaConfigured' => $this->securityService->isCaptchaConfigured(), |
| 67 |
// ] |
| 68 |
], |
| 69 |
'general' => [ |
| 70 |
'wcagBackend' => $allSettings['general']['wcagBackend'] ?? false, |
| 71 |
'favoriteTemplates' => $allSettings['general']['favoriteTemplates'] ?? [], |
| 72 |
'delete_on_uninstall' => $allSettings['general']['delete_on_uninstall'] ?? false, |
| 73 |
// Future general settings can be added here: |
| 74 |
// 'site_settings' => $allSettings['general']['site_settings'] ?? null, |
| 75 |
// 'form_defaults' => $allSettings['general']['form_defaults'] ?? null, |
| 76 |
'changelog_version' => $allSettings['general']['changelog_version'] ?? '', |
| 77 |
], |
| 78 |
'integrations' => [ |
| 79 |
'wpdatatables' => array_merge( |
| 80 |
$allSettings['integrations']['wpdatatables'] ?? ['enabled' => false], |
| 81 |
[ |
| 82 |
'connected' => class_exists('WPDataTable') || defined('WDT_ROOT_PATH') |
| 83 |
] |
| 84 |
), |
| 85 |
// Future categories can be added here |
| 86 |
], |
| 87 |
]; |
| 88 |
|
| 89 |
/** |
| 90 |
* Filter to allow Pro plugin to add additional settings data |
| 91 |
* |
| 92 |
* @param array $organizedSettings The organized settings array |
| 93 |
* @param array $allSettings The raw settings from database |
| 94 |
* |
| 95 |
* @since 1.0.0 |
| 96 |
*/ |
| 97 |
$organizedSettings = apply_filters('ivyforms/global/settings/get_all', $organizedSettings, $allSettings); |
| 98 |
|
| 99 |
return new WP_REST_Response([ |
| 100 |
'message' => BackendStrings::getSettingsStrings()['all_settings_retrieved'], |
| 101 |
'data' => $organizedSettings |
| 102 |
], 200); |
| 103 |
} |
| 104 |
} |
| 105 |
|