| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Settings hook for activation |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace IvyForms\Services\InstallActions; |
| 8 |
|
| 9 |
// phpcs:disable PSR1.Files.SideEffects |
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
exit; // Exit if accessed directly |
| 12 |
} |
| 13 |
|
| 14 |
use Exception; |
| 15 |
use IvyForms\Services\Settings\SettingsService; |
| 16 |
|
| 17 |
/** |
| 18 |
* Class ActivationSettingsHook |
| 19 |
* |
| 20 |
* @package IvyForms\Services\InstallActions |
| 21 |
*/ |
| 22 |
class ActivationSettingsHook |
| 23 |
{ |
| 24 |
/** |
| 25 |
* Initialize the plugin |
| 26 |
* |
| 27 |
* @throws Exception |
| 28 |
*/ |
| 29 |
public static function init(): void |
| 30 |
{ |
| 31 |
self::initGeneralSettings(); |
| 32 |
self::initIntegrationsSettings(); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* @param string $category |
| 37 |
* @param mixed[] $settings |
| 38 |
*/ |
| 39 |
public static function initSettings(string $category, array $settings): void |
| 40 |
{ |
| 41 |
$settingsStorage = new SettingsService(); |
| 42 |
|
| 43 |
if (!$settingsStorage->getCategorySettings($category)) { |
| 44 |
$settingsStorage->setCategorySettings( |
| 45 |
$category, |
| 46 |
[] |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
foreach ($settings as $key => $value) { |
| 51 |
if (null === $settingsStorage->getSetting($category, $key)) { |
| 52 |
$settingsStorage->setSetting( |
| 53 |
$category, |
| 54 |
$key, |
| 55 |
$value |
| 56 |
); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Init General Settings |
| 63 |
*/ |
| 64 |
private static function initGeneralSettings(): void |
| 65 |
{ |
| 66 |
|
| 67 |
$settings = [ |
| 68 |
'version' => IVYFORMS_VERSION, |
| 69 |
'changelog_version' => '', |
| 70 |
'fullscreen' => false, |
| 71 |
]; |
| 72 |
|
| 73 |
self::initSettings('general', $settings); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Init Integrations Settings |
| 78 |
*/ |
| 79 |
private static function initIntegrationsSettings(): void |
| 80 |
{ |
| 81 |
$settings = [ |
| 82 |
'wpdatatables' => [ |
| 83 |
'enabled' => false, |
| 84 |
], |
| 85 |
// Future integrations can be added here |
| 86 |
// 'mailchimp' => [ |
| 87 |
// 'enabled' => false, |
| 88 |
// ], |
| 89 |
]; |
| 90 |
|
| 91 |
self::initSettings('integrations', $settings); |
| 92 |
} |
| 93 |
} |
| 94 |
|