PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
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 / Plugin / PluginInstallLifecycle.php

PluginInstallLifecycle.php in The Innovative Form Builder – IvyForms 1.5, at backend/src/Plugin/PluginInstallLifecycle.php

101 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin install, activation, and uninstall lifecycle hooks.
5 *
6 * @package IvyForms
7 * @since 0.1.0
8 */
9
10 namespace IvyForms\Plugin;
11
12 use Exception;
13 use IvyForms\Common\Exceptions\InvalidArgumentException;
14 use IvyForms\Services\InstallActions\ActivationDatabaseHook;
15 use IvyForms\Services\InstallActions\ActivationMultisite;
16 use IvyForms\Services\InstallActions\ActivationNewSiteMultisite;
17 use IvyForms\Services\InstallActions\ActivationCapabilitiesHook;
18 use IvyForms\Services\InstallActions\ActivationSettingsHook;
19 use IvyForms\Services\InstallActions\DeleteDatabaseHook;
20 use IvyForms\Services\InstallActions\DeletionMultisite;
21 use IvyForms\Services\Permissions\AccessRulesCapabilityBootstrap;
22 use IvyForms\Services\Settings\SettingsService;
23
24 /**
25 * Handles WordPress activation / deactivation / uninstall callbacks.
26 */
27 class PluginInstallLifecycle
28 {
29 /**
30 * @param bool $networkWide
31 * @throws InvalidArgumentException
32 */
33 public static function activation(bool $networkWide): void
34 {
35 //Network activation
36 if ($networkWide && function_exists('is_multisite') && is_multisite()) {
37 ActivationMultisite::init();
38 }
39
40 ActivationDatabaseHook::init();
41 ActivationCapabilitiesHook::ensureAdministratorCaps();
42 }
43
44 /**
45 * Ensures IvyForms capabilities exist on the Administrator role after upgrades.
46 */
47 public static function maybeEnsureAdministratorCapabilities(): void
48 {
49 if (!is_admin()) {
50 return;
51 }
52 ActivationCapabilitiesHook::ensureAdministratorCapsIfMissing();
53 AccessRulesCapabilityBootstrap::maybeRunOnce();
54 }
55
56 /**
57 * @param int $siteId
58 * @throws InvalidArgumentException
59 */
60 public static function initNewSite(int $siteId): void
61 {
62 ActivationNewSiteMultisite::init($siteId);
63 }
64
65 /**
66 * @throws Exception
67 */
68 public static function activationSettings(): void
69 {
70 ActivationSettingsHook::init();
71 }
72
73 /**
74 * Plugin deactivation: intentionally does not delete data (see {@see self::deletion()}).
75 */
76 public static function deactivation(): void
77 {
78 }
79
80 /**
81 * Uninstall function when plugin is deleted
82 * @throws InvalidArgumentException
83 */
84 public static function deletion(): void
85 {
86 $settingsService = new SettingsService();
87
88 if ($settingsService->getSetting('general', 'delete_on_uninstall')) {
89 //Network deletion
90 if (
91 function_exists('is_multisite') &&
92 is_multisite()
93 ) {
94 DeletionMultisite::delete();
95 }
96
97 DeleteDatabaseHook::delete();
98 }
99 }
100 }
101