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