PluginProbe
The Innovative Form Builder – IvyForms / 0.1.2
The Innovative Form Builder – IvyForms v0.1.2
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
ivyforms / backend / src / Services / InstallActions / ActivationSettingsHook.php

ActivationSettingsHook.php in The Innovative Form Builder – IvyForms 0.1.2, at backend/src/Services/InstallActions/ActivationSettingsHook.php

72 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
33
34 /**
35 * @param string $category
36 * @param mixed[] $settings
37 */
38 public static function initSettings(string $category, array $settings): void
39 {
40 $settingsStorage = new SettingsService();
41
42 if (!$settingsStorage->getCategorySettings($category)) {
43 $settingsStorage->setCategorySettings(
44 $category,
45 []
46 );
47 }
48
49 foreach ($settings as $key => $value) {
50 if (null === $settingsStorage->getSetting($category, $key)) {
51 $settingsStorage->setSetting(
52 $category,
53 $key,
54 $value
55 );
56 }
57 }
58 }
59
60 /**
61 * Init General Settings
62 */
63 private static function initGeneralSettings(): void
64 {
65 $settings = [
66 'itemsPerPage' => 12,
67 ];
68
69 self::initSettings('general', $settings);
70 }
71 }
72