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
← All changes | backend/src/Plugin/Plugin.php +29 -83 1.1 → 1.5 View file →
@@ -13,21 +13,18 @@
13 13 use IvyForms\Common\Exceptions\InvalidArgumentException;
14 14 use IvyForms\Common\Exceptions\ValidationException;
15 15 use IvyForms\Routes\Routes;
16 16 use IvyForms\Services\InstallActions\ActivationDatabaseHook;
17 -use IvyForms\Services\InstallActions\ActivationMultisite;
18 -use IvyForms\Services\InstallActions\ActivationNewSiteMultisite;
19 -use IvyForms\Services\InstallActions\ActivationSettingsHook;
20 -use IvyForms\Services\InstallActions\DeleteDatabaseHook;
21 -use IvyForms\Services\InstallActions\DeletionMultisite;
22 17 use IvyForms\Services\Integrations\Elementor\IvyFormsElementorLoader;
23 18 use IvyForms\Services\Integrations\Gutenberg\Blocks\GutenbergBlock;
24 19 use IvyForms\Services\Integrations\IntegrationService;
25 20 use IvyForms\Services\Menu\MenuManager;
21 +use IvyForms\Services\Payment\PaymentCspHeaders;
26 22 use IvyForms\Services\Preview\PreviewService;
27 23 use IvyForms\Services\Settings\SettingsService;
28 24 use IvyForms\Services\Shortcode\Helpers\ShortcodeHelper;
29 25 use IvyForms\Services\Shortcode\ShortcodeService;
26 +use IvyForms\Services\Usage\UsageTrackingService;
30 27 use IvyForms\Vendor\DI\Container;
31 28 use IvyForms\Vendor\DI\ContainerBuilder;
32 29 use IvyForms\Vendor\DI\DependencyException;
33 30 use IvyForms\Vendor\DI\NotFoundException;
@@ -96,13 +93,13 @@
96 93 * The code that runs during plugin activation
97 94 */
98 95 register_activation_hook(
99 96 IVYFORMS_FILE,
100 - [ self::class, 'activation' ]
97 + [ PluginInstallLifecycle::class, 'activation' ]
101 98 );
102 99 register_activation_hook(
103 100 IVYFORMS_FILE,
104 - [ self::class, 'activationSettings' ]
101 + [ PluginInstallLifecycle::class, 'activationSettings' ]
105 102 );
106 103
107 104 /**
108 105 * The code that runs during plugin deactivation
@@ -108,9 +105,9 @@
108 105 * The code that runs during plugin deactivation
109 106 */
110 107 register_deactivation_hook(
111 108 IVYFORMS_FILE,
112 - [ self::class, 'deactivation' ]
109 + [ PluginInstallLifecycle::class, 'deactivation' ]
113 110 );
114 111
115 112 /**
116 113 * The code that runs when plugin is deleted
@@ -116,14 +113,16 @@
116 113 * The code that runs when plugin is deleted
117 114 */
118 115 register_uninstall_hook(
119 116 IVYFORMS_FILE,
120 - [ self::class, 'deletion']
117 + [ PluginInstallLifecycle::class, 'deletion']
121 118 );
122 119
123 120 /** Init load */
124 121 add_action('plugins_loaded', [ $this, 'init' ]);
125 122
123 + add_action('init', [PluginInstallLifecycle::class, 'maybeEnsureAdministratorCapabilities'], 0);
124 +
126 125 /** Load translations at init action (WordPress 6.7+ requirement) */
127 126 add_action('init', [ $this, 'loadTranslations' ]);
128 127
129 128 /** Register API calls */
@@ -133,9 +132,9 @@
133 132 add_action('wp_ajax_ivyforms_api', [ $this, 'registerRoutes' ]);
134 133 add_action('wp_ajax_nopriv_ivyforms_api', [ $this, 'registerRoutes' ]);
135 134
136 135 /** Activation hook for new site on multisite setup */
137 - add_action('wpmu_new_blog', [ $this, 'initNewSite' ]);
136 + add_action('wpmu_new_blog', [ PluginInstallLifecycle::class, 'initNewSite' ]);
138 137
139 138 add_filter('wp_script_attributes', ['IvyForms\Services\Shortcode\ShortcodeService', 'addScriptAttribute']);
140 139
141 140 // Register admin hooks via AdminHooks class
@@ -151,83 +150,10 @@
151 150 {
152 151 // Register REST API routes after the container is built
153 152 Routes::registerRoutes($this->container);
154 153 }
155 - /**
156 - * @param bool $networkWide
157 - * @throws InvalidArgumentException
158 - */
159 - public static function activation(bool $networkWide): void
160 - {
161 - //Network activation
162 - if ($networkWide && function_exists('is_multisite') && is_multisite()) {
163 - ActivationMultisite::init();
164 - }
165 154
166 - ActivationDatabaseHook::init();
167 - }
168 -
169 155 /**
170 - * @param int $siteId
171 - * @throws InvalidArgumentException
172 - */
173 - public static function initNewSite(int $siteId): void
174 - {
175 - ActivationNewSiteMultisite::init($siteId);
176 - }
177 -
178 - /**
179 - * @throws Exception
180 - */
181 - public static function activationSettings(): void
182 - {
183 - ActivationSettingsHook::init();
184 - }
185 -
186 - /**
187 - * Deactivation function when plugin is deactivated
188 - * Deletes all IvyForms data if delete_on_uninstall is enabled
189 - * @throws InvalidArgumentException
190 - */
191 - public static function deactivation(): void
192 - {
193 - $settingsService = new SettingsService();
194 -
195 - if ($settingsService->getSetting('general', 'delete_on_uninstall')) {
196 - //Network deletion
197 - if (
198 - function_exists('is_multisite') &&
199 - is_multisite()
200 - ) {
201 - DeletionMultisite::delete();
202 - }
203 -
204 - DeleteDatabaseHook::delete();
205 - }
206 - }
207 -
208 - /**
209 - * Uninstall function when plugin is deleted
210 - * @throws InvalidArgumentException
211 - */
212 - public static function deletion(): void
213 - {
214 - $settingsService = new SettingsService();
215 -
216 - if ($settingsService->getSetting('general', 'delete_on_uninstall')) {
217 - //Network deletion
218 - if (
219 - function_exists('is_multisite') &&
220 - is_multisite()
221 - ) {
222 - DeletionMultisite::delete();
223 - }
224 -
225 - DeleteDatabaseHook::delete();
226 - }
227 - }
228 -
229 - /**
230 156 * Init
231 157 * @return void
232 158 * @throws ValidationException|InvalidArgumentException
233 159 */
@@ -236,10 +162,12 @@
236 162 new PreviewService();
237 163 $this->initIntegrationService();
238 164 $this->initMenuManager();
239 165 $this->registerShortcode();
166 + PaymentCspHeaders::register();
240 167 $this->registerGutenbergBlock();
241 168 $this->registerElementorWidget();
169 + $this->initUsageTrackingService();
242 170 }
243 171
244 172 /**
245 173 * Initialize integration service
@@ -254,8 +182,26 @@
254 182 $integrationService->init();
255 183 } catch (DependencyException | NotFoundException $e) {
256 184 if (defined('WP_DEBUG') && WP_DEBUG) {
257 185 error_log('Integration service error: ' . $e->getMessage());
186 + }
187 + }
188 + }
189 +
190 + /**
191 + * Initialize usage tracking service
192 + *
193 + * @return void
194 + */
195 + private function initUsageTrackingService(): void
196 + {
197 + try {
198 + /** @var UsageTrackingService $usageTrackingService */
199 + $usageTrackingService = $this->container->get(UsageTrackingService::class);
200 + $usageTrackingService->init();
201 + } catch (DependencyException | NotFoundException $e) {
202 + if (defined('WP_DEBUG') && WP_DEBUG) {
203 + error_log('Usage tracking service error: ' . $e->getMessage());
258 204 }
259 205 }
260 206 }
261 207