PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / trunk
Subscriptions for WooCommerce with Stripe Recurring Payments vtrunk
1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 All 60 releases
subscription / includes / Admin / Integrations.php

Integrations.php in Subscriptions for WooCommerce with Stripe Recurring Payments trunk, at includes/Admin/Integrations.php

680 lines 23.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SpringDevs\Subscription\Admin;
4
5 // Exit if accessed directly.
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 /**
11 * Integrations class
12 *
13 * @package SpringDevs\Subscription\Admin
14 */
15 class Integrations {
16 /**
17 * Integrations list.
18 *
19 * @var array
20 */
21 protected $integrations = [];
22
23 /**
24 * Initialize the class
25 */
26 public function __construct() {
27 // Initialize.
28 add_action( 'init', [ $this, 'init' ], 10 );
29
30 // Admin menu (sidebar).
31 add_action( 'admin_menu', array( $this, 'register_admin_menu' ), 20 );
32
33 // WPSubscription navbar.
34 add_filter( 'subscrpt_admin_header_menu_items', [ $this, 'add_integrations_menu_item' ], 10, 2 );
35
36 // Enqueue integrations scripts.
37 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_integrations_scripts' ] );
38
39 // Integrations AJAX handler.
40 // add_action( 'admin_ajax_integrations_handler', [ $this,'integrations_handler_callback' ] );
41 // add_action( 'admin_ajax_nopriv_integrations_handler', [ $this,'integrations_handler_callback' ] );
42 }
43
44 /**
45 * Initialize the integrations.
46 */
47 public function init() {
48 // Set integrations.
49 $this->integrations = $this->get_integrations();
50 }
51
52 /**
53 * Register submenu under `subscriptions` menu.
54 *
55 * @return void
56 */
57 public function register_admin_menu() {
58 $parent_slug = 'wp-subscription';
59 add_submenu_page(
60 $parent_slug,
61 __( 'Integrations', 'subscription' ),
62 __( 'Integrations', 'subscription' ),
63 'manage_options',
64 'wp-subscription-integrations',
65 [ $this, 'render_integrations_page' ],
66 );
67 }
68
69 /**
70 * Add Integrations link to the WPSubscription admin header menu.
71 *
72 * @param array $menu_items Array of menu items.
73 * @param string $current Current active menu item slug.
74 */
75 public function add_integrations_menu_item( $menu_items, $current ) {
76 $menu_items[] = [
77 'slug' => 'wp-subscription-integrations',
78 'label' => __( 'Integrations', 'subscription' ),
79 'url' => admin_url( 'admin.php?page=wp-subscription-integrations' ),
80 ];
81 return $menu_items;
82 }
83
84 /**
85 * Enqueue scripts for integrations page.
86 */
87 public function enqueue_integrations_scripts() {
88 $screen = get_current_screen();
89 if ( ! $screen || false === strpos( $screen->id, 'wp-subscription-integrations' ) ) {
90 return;
91 }
92
93 wp_enqueue_script( 'subscrpt-integrations', SUBSCRPT_ASSETS . '/js/integration_settings.js', [], SUBSCRPT_VERSION, true );
94
95 wp_localize_script(
96 'subscrpt-integrations',
97 'subscrptIntegrations',
98 array(
99 'nonce' => wp_create_nonce( 'subscrpt_integration_install_nonce' ),
100 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
101 )
102 );
103 }
104
105 /**
106 * Handle AJAX request for integrations.
107 */
108 public function integrations_handler_callback() {
109 check_ajax_referer( 'wp_subs_integrations_nonce', 'nonce' );
110
111 $action_callback = ! empty( $_POST['action_callback'] ) ? sanitize_text_field( wp_unslash( $_POST['action_callback'] ) ) : '';
112
113 dd( '🔽 action_callback', $action_callback );
114 }
115
116 /**
117 * Check if a payment gateway is installed and active.
118 *
119 * @param string $gateway_id Gateway ID.
120 * @param bool $partial_match Whether to allow partial match of gateway ID.
121 * @return bool
122 */
123 public static function is_gateway_installed( $gateway_id, $partial_match = false ) {
124 $installed_gateways = WC()->payment_gateways()->payment_gateways();
125
126 // Partial match check. For gateways with dynamic IDs.
127 if ( $partial_match ) {
128 foreach ( $installed_gateways as $key => $gateway ) {
129 if ( strpos( $key, $gateway_id ) !== false ) {
130 return true;
131 }
132 }
133 return false;
134 }
135
136 return isset( $installed_gateways[ $gateway_id ] );
137 }
138
139 /**
140 * Check if a payment gateway is enabled.
141 *
142 * @param string $gateway_id Gateway ID.
143 * @param bool $partial_match Whether to allow partial match of gateway ID.
144 * @return bool
145 */
146 public static function is_gateway_enabled( $gateway_id, $partial_match = false ) {
147 $installed_gateways = WC()->payment_gateways()->payment_gateways();
148
149 // Partial match check. For gateways with dynamic IDs.
150 if ( $partial_match ) {
151 foreach ( $installed_gateways as $key => $gateway ) {
152 if ( strpos( $key, $gateway_id ) !== false ) {
153 return $gateway->is_available();
154 }
155 }
156 return false;
157 }
158
159 if ( ! isset( $installed_gateways[ $gateway_id ] ) ) {
160 return false;
161 }
162 return $installed_gateways[ $gateway_id ]->is_available();
163 }
164
165
166
167 /**
168 * Check if a gateway is installed by plugin file.
169 *
170 * @param string $plugin_file Plugin file path.
171 * @return bool
172 */
173 protected function is_plugin_installed( $plugin_file ) {
174 if ( ! function_exists( 'get_plugins' ) ) {
175 require_once ABSPATH . 'wp-admin/includes/plugin.php';
176 }
177 $plugins = get_plugins();
178 return isset( $plugins[ $plugin_file ] );
179 }
180
181 /**
182 * Check if a gateway plugin is active.
183 *
184 * @param string $plugin_file Plugin file path.
185 * @return bool
186 */
187 protected function is_plugin_active( $plugin_file ) {
188 return is_plugin_active( $plugin_file );
189 }
190
191 /**
192 * Check if a payment gateway is enabled.
193 *
194 * @param string $gateway_id Gateway ID.
195 */
196 public function is_payment_gateway_enabled( $gateway_id ) {
197 $gateways = WC()->payment_gateways->get_available_payment_gateways();
198 return isset( $gateways[ $gateway_id ] );
199 }
200
201 /**
202 * Get the list of integrations.
203 *
204 * @return array
205 */
206 protected function get_integrations(): array {
207 $integrations = [
208 'paypal' => [
209 'title' => 'PayPal',
210 'description' => 'Accept recurring subscription payments directly through PayPal.',
211 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/paypal.svg',
212 'type' => 'payment_gateway',
213 'is_installed' => 'on' === get_option( 'wp_subs_paypal_integration_enabled', 'off' ),
214 'is_active' => self::is_gateway_enabled( 'wp_subscription_paypal' ),
215 'supports_recurring' => true,
216 'actions' => [
217 // [
218 // 'action' => 'install',
219 // 'label' => 'Install Now',
220 // 'type' => 'function',
221 // 'function' => 'wpSubsInstallPaypalIntegration()',
222 // ],
223 [
224 'action' => 'settings',
225 'label' => 'Settings',
226 'type' => 'link',
227 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wp_subscription_paypal' ),
228 ],
229 // [
230 // 'action' => 'uninstall',
231 // 'label' => 'Uninstall',
232 // 'type' => 'function',
233 // 'function' => 'wpSubsUninstallPaypalIntegration()',
234 // 'class' => 'button button-primary wp-subs-button-danger',
235 // ],
236 ],
237 ],
238 'stripe' => [
239 'title' => 'Stripe',
240 'description' => 'Process subscription payments securely with Stripe.',
241 'icon_url' => 'https://ps.w.org/woocommerce-gateway-stripe/assets/icon-256x256.png',
242 'type' => 'payment_gateway',
243 'is_installed' => class_exists( 'WC_Stripe' ),
244 'is_active' => self::is_gateway_enabled( 'stripe' ),
245 'supports_recurring' => true,
246 'actions' => [
247 [
248 'action' => 'install',
249 'label' => 'Install Now',
250 'type' => 'function',
251 'function' => "subscrptInstallPlugin(this, 'woocommerce-gateway-stripe')",
252 ],
253 [
254 'action' => 'settings',
255 'label' => 'Settings',
256 'type' => 'link',
257 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe&panel=settings' ),
258 ],
259 ],
260 ],
261 'paddle' => [
262 'title' => 'Paddle',
263 'description' => 'Process subscription payments securely with Paddle.',
264 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/paddle.svg',
265 'type' => 'payment_gateway',
266 'is_installed' => class_exists( 'SmartPayWoo\Gateways\Paddle\SmartPay_Paddle' ),
267 'is_active' => self::is_gateway_enabled( 'smartpay_paddle' ),
268 'supports_recurring' => true,
269 'actions' => [
270 [
271 'action' => 'install',
272 'label' => 'Get Paddle',
273 'type' => 'external_link',
274 'url' => 'https://wpsmartpay.com/paddle-for-woocommerce/',
275 ],
276 [
277 'action' => 'enable',
278 'label' => 'Enable Gateway',
279 'type' => 'toggle_option',
280 'option_key' => 'woocommerce_enable_paddle_gateway',
281 'value' => true,
282 ],
283 [
284 'action' => 'settings',
285 'label' => 'Settings',
286 'type' => 'link',
287 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=smartpay_paddle&from=WCADMIN_PAYMENT_SETTINGS' ),
288 ],
289 [
290 'label' => 'More Details',
291 'type' => 'external_link',
292 'url' => 'https://wpsmartpay.com/paddle-for-woocommerce/',
293 ],
294 ],
295 ],
296 'mollie' => [
297 'title' => 'Mollie',
298 'description' => 'Pay for subscriptions with Mollie Payments for WooCommerce.',
299 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/mollie.png',
300 'type' => 'payment_gateway',
301 'is_pro' => true,
302 'is_installed' => class_exists( 'Mollie\WooCommerce\Activation\ActivationModule' ),
303 'is_active' => self::is_gateway_enabled( 'mollie_wc_gateway', true ),
304 'supports_recurring' => true,
305 'actions' => [
306 [
307 'action' => 'install',
308 'label' => 'Install Now',
309 'type' => 'function',
310 'function' => "subscrptInstallPlugin(this, 'mollie-payments-for-woocommerce')",
311 ],
312 [
313 'action' => 'settings',
314 'label' => 'Settings',
315 'type' => 'link',
316 'url' => admin_url( 'admin.php?page=wc-settings&tab=mollie_settings' ),
317 ],
318 [
319 'label' => 'More Details',
320 'type' => 'external_link',
321 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-payment-with-mollie?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
322 ],
323 ],
324 ],
325 'razorpay' => [
326 'title' => 'Razorpay',
327 'description' => 'Pay for subscriptions securely with Razorpay for WooCommerce.',
328 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/razorpay.png',
329 'type' => 'payment_gateway',
330 'is_pro' => true,
331 'is_beta' => true,
332 'is_installed' => class_exists( 'WC_Razorpay' ),
333 'is_active' => self::is_gateway_enabled( 'razorpay' ),
334 'supports_recurring' => true,
335 'actions' => [
336 [
337 'action' => 'install',
338 'label' => 'Install Now',
339 'type' => 'function',
340 'function' => "subscrptInstallPlugin(this, 'woo-razorpay')",
341 ],
342 [
343 'action' => 'settings',
344 'label' => 'Settings',
345 'type' => 'link',
346 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=razorpay' ),
347 ],
348 [
349 'label' => 'More Details',
350 'type' => 'external_link',
351 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-payment-with-razorpay?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
352 ],
353 ],
354 ],
355 'xendit' => [
356 'title' => 'Xendit',
357 'description' => 'Pay for subscriptions securely with Xendit for WooCommerce.',
358 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/xendit.png',
359 'type' => 'payment_gateway',
360 'is_pro' => true,
361 'is_beta' => true,
362 'is_installed' => class_exists( 'WC_Xendit_CC' ),
363 'is_active' => self::is_gateway_enabled( 'xendit' ),
364 'supports_recurring' => true,
365 'actions' => [
366 [
367 'action' => 'install',
368 'label' => 'Install Now',
369 'type' => 'function',
370 'function' => "subscrptInstallPlugin(this, 'woo-xendit-virtual-accounts')",
371 ],
372 [
373 'action' => 'settings',
374 'label' => 'Settings',
375 'type' => 'link',
376 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=xendit_gateway' ),
377 ],
378 [
379 'label' => 'More Details',
380 'type' => 'external_link',
381 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-payment-with-xendit?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
382 ],
383 ],
384 ],
385 ];
386
387 // Third-party integrations (requires Pro plugin to function).
388 $third_party = [
389 // LMS.
390 'tutor_lms' => [
391 'title' => 'Tutor LMS',
392 'description' => 'Restrict course access based on subscription status. Enroll and unenroll students automatically.',
393 'icon_url' => 'https://ps.w.org/tutor/assets/icon-256x256.gif',
394 'type' => 'third_party',
395 'is_pro' => true,
396 'category' => 'lms',
397 'is_installed' => is_plugin_active( 'tutor/tutor.php' ) && class_exists( 'TUTOR\Tutor' ),
398 'is_active' => is_plugin_active( 'tutor/tutor.php' ) && class_exists( 'TUTOR\Tutor' ),
399 'actions' => [
400 [
401 'action' => 'install',
402 'label' => __( 'Install Now', 'subscription' ),
403 'type' => 'function',
404 'function' => "subscrptInstallPlugin(this, 'tutor')",
405 ],
406 [
407 'label' => __( 'Learn More', 'subscription' ),
408 'type' => 'external_link',
409 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-tutor-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
410 ],
411 ],
412 ],
413 'learnpress' => [
414 'title' => 'LearnPress',
415 'description' => 'Connect subscriptions with LearnPress courses. Enroll users automatically when subscriptions are active.',
416 'icon_url' => 'https://ps.w.org/learnpress/assets/icon-256x256.gif',
417 'type' => 'third_party',
418 'is_pro' => true,
419 'category' => 'lms',
420 'is_installed' => is_plugin_active( 'learnpress/learnpress.php' ) && class_exists( 'LearnPress' ),
421 'is_active' => is_plugin_active( 'learnpress/learnpress.php' ) && class_exists( 'LearnPress' ),
422 'actions' => [
423 [
424 'action' => 'install',
425 'label' => __( 'Install Now', 'subscription' ),
426 'type' => 'function',
427 'function' => "subscrptInstallPlugin(this, 'learnpress')",
428 ],
429 [
430 'label' => __( 'Learn More', 'subscription' ),
431 'type' => 'external_link',
432 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-learnpress-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
433 ],
434 ],
435 ],
436 'learndash' => [
437 'title' => 'LearnDash',
438 'description' => 'Sync subscription status with LearnDash group enrollment and course access.',
439 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/learndash.jpeg',
440 'type' => 'third_party',
441 'is_pro' => true,
442 'category' => 'lms',
443 'is_installed' => is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) && class_exists( 'LearnDash\Core\App' ),
444 'is_active' => is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) && class_exists( 'LearnDash\Core\App' ),
445 'actions' => [
446 [
447 'action' => 'install',
448 'label' => __( 'Get LearnDash', 'subscription' ),
449 'type' => 'external_link',
450 'url' => 'https://www.learndash.com/',
451 ],
452 [
453 'label' => __( 'Learn More', 'subscription' ),
454 'type' => 'external_link',
455 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-learndash-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
456 ],
457 ],
458 ],
459 // CRM.
460 'fluentcrm' => [
461 'title' => 'FluentCRM',
462 'description' => 'Trigger email sequences and manage contacts based on subscription events and status changes.',
463 'icon_url' => 'https://ps.w.org/fluent-crm/assets/icon-256x256.png',
464 'type' => 'third_party',
465 'is_pro' => true,
466 'category' => 'crm',
467 'is_installed' => class_exists( 'FluentCrm\App\Services\Funnel\BaseTrigger' ),
468 'is_active' => class_exists( 'FluentCrm\App\Services\Funnel\BaseTrigger' ),
469 'actions' => [
470 [
471 'action' => 'install',
472 'label' => __( 'Install Now', 'subscription' ),
473 'type' => 'function',
474 'function' => "subscrptInstallPlugin(this, 'fluent-crm')",
475 ],
476 [
477 'label' => __( 'Learn More', 'subscription' ),
478 'type' => 'external_link',
479 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-fluent-crm?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
480 ],
481 ],
482 ],
483 // Automation.
484 'automatorwp' => [
485 'title' => 'AutomatorWP',
486 'description' => 'Build powerful automations triggered by subscription events without writing any code.',
487 'icon_url' => 'https://ps.w.org/automatorwp/assets/icon-256x256.png',
488 'type' => 'third_party',
489 'is_pro' => true,
490 'category' => 'automation',
491 'is_installed' => is_plugin_active( 'automatorwp/automatorwp.php' ) && class_exists( 'AutomatorWP' ),
492 'is_active' => is_plugin_active( 'automatorwp/automatorwp.php' ) && class_exists( 'AutomatorWP' ),
493 'actions' => [
494 [
495 'action' => 'install',
496 'label' => __( 'Install Now', 'subscription' ),
497 'type' => 'function',
498 'function' => "subscrptInstallPlugin(this, 'automatorwp')",
499 ],
500 // [
501 // 'label' => __( 'Learn More', 'subscription' ),
502 // 'type' => 'external_link',
503 // 'url' => 'https://docs.wpsubscription.co/en/',
504 // ],
505 ],
506 ],
507 'wpfusion' => [
508 'title' => 'WP Fusion',
509 'description' => 'Sync subscription data with your CRM and marketing platforms through WP Fusion.',
510 'icon_url' => 'https://ps.w.org/wp-fusion-lite/assets/icon-256x256.png',
511 'type' => 'third_party',
512 'is_pro' => true,
513 'category' => 'automation',
514 'is_installed' => class_exists( 'WPF_Integrations_Base' ),
515 'is_active' => class_exists( 'WPF_Integrations_Base' ),
516 'actions' => [
517 [
518 'action' => 'install',
519 'label' => __( 'Get WP Fusion', 'subscription' ),
520 'type' => 'external_link',
521 'url' => 'https://wpfusion.com/',
522 ],
523 // [
524 // 'label' => __( 'Learn More', 'subscription' ),
525 // 'type' => 'external_link',
526 // 'url' => 'https://docs.wpsubscription.co/en/',
527 // ],
528 ],
529 ],
530 // Email Marketing.
531 'mailpoet' => [
532 'title' => 'MailPoet',
533 'description' => 'Add subscribers to MailPoet lists and trigger email automations based on subscription lifecycle events.',
534 'icon_url' => 'https://ps.w.org/mailpoet/assets/icon-256x256.png',
535 'type' => 'third_party',
536 'is_pro' => true,
537 'category' => 'email',
538 'is_installed' => is_plugin_active( 'mailpoet/mailpoet.php' ) || is_plugin_active( 'mailpoet-premium/mailpoet-premium.php' ),
539 'is_active' => is_plugin_active( 'mailpoet/mailpoet.php' ) || is_plugin_active( 'mailpoet-premium/mailpoet-premium.php' ),
540 'actions' => [
541 [
542 'action' => 'install',
543 'label' => __( 'Install Now', 'subscription' ),
544 'type' => 'function',
545 'function' => "subscrptInstallPlugin(this, 'mailpoet')",
546 ],
547 [
548 'label' => __( 'Learn More', 'subscription' ),
549 'type' => 'external_link',
550 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-mailpoet?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
551 ],
552 ],
553 ],
554 // License Management.
555 'wp_soft_lic' => [
556 'title' => 'WP Software License',
557 'description' => 'Issue and validate software licenses for subscription-based digital products.',
558 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/wp-software-license.png',
559 'type' => 'third_party',
560 'is_pro' => true,
561 'category' => 'license',
562 'is_installed' => is_plugin_active( 'software-license/software-license.php' ) && class_exists( 'WOO_SL' ),
563 'is_active' => is_plugin_active( 'software-license/software-license.php' ) && class_exists( 'WOO_SL' ),
564 'actions' => [
565 [
566 'action' => 'install',
567 'label' => __( 'Get Plugin', 'subscription' ),
568 'type' => 'external_link',
569 'url' => 'https://wpsoftwarelicense.com/',
570 ],
571 // [
572 // 'label' => __( 'Learn More', 'subscription' ),
573 // 'type' => 'external_link',
574 // 'url' => 'https://docs.wpsubscription.co/en/',
575 // ],
576 ],
577 ],
578 'license_mgr' => [
579 'title' => 'License Manager for WooCommerce',
580 'description' => 'Generate and manage software license keys that are automatically tied to active subscriptions.',
581 'icon_url' => 'https://ps.w.org/license-manager-for-woocommerce/assets/icon-256x256.gif',
582 'type' => 'third_party',
583 'is_pro' => true,
584 'category' => 'license',
585 'is_installed' => is_plugin_active( 'license-manager-for-woocommerce/license-manager-for-woocommerce.php' ) && class_exists( 'LicenseManagerForWooCommerce\Models\Resources\License' ),
586 'is_active' => is_plugin_active( 'license-manager-for-woocommerce/license-manager-for-woocommerce.php' ) && class_exists( 'LicenseManagerForWooCommerce\Models\Resources\License' ),
587 'actions' => [
588 [
589 'action' => 'install',
590 'label' => __( 'Install Now', 'subscription' ),
591 'type' => 'function',
592 'function' => "subscrptInstallPlugin(this, 'license-manager-for-woocommerce')",
593 ],
594 // [
595 // 'label' => __( 'Learn More', 'subscription' ),
596 // 'type' => 'external_link',
597 // 'url' => 'https://docs.wpsubscription.co/en/',
598 // ],
599 ],
600 ],
601 ];
602 $integrations = array_merge( $integrations, $third_party );
603
604 // Add more integrations as needed.
605 $integrations = apply_filters( 'wpsubs_integrations', $integrations );
606
607 return $integrations;
608 }
609
610 /**
611 * Filter actions.
612 *
613 * @param array $integrations Integrations array.
614 */
615 protected function filter_integration_actions( array $integrations ): array {
616 $cleaned_integrations = [];
617
618 foreach ( $integrations as $integration ) {
619 $is_installed = $integration['is_installed'] ?? false;
620 $is_active = $integration['is_active'] ?? false;
621
622 $cleaned_actions = [];
623
624 foreach ( $integration['actions'] as $integration_action ) {
625 $action_tag = $integration_action['action'] ?? null;
626
627 if ( 'install' === $action_tag ) {
628 if ( ! $is_installed ) {
629 $cleaned_actions[] = $integration_action;
630 }
631 continue;
632 }
633 if ( 'uninstall' === $action_tag ) {
634 if ( $is_installed ) {
635 $cleaned_actions[] = $integration_action;
636 }
637 continue;
638 }
639 if ( 'enable' === $action_tag ) {
640 if ( $is_installed && ! $is_active ) {
641 $cleaned_actions[] = $integration_action;
642 }
643 continue;
644 }
645 if ( 'settings' === $action_tag ) {
646 if ( $is_installed ) {
647 $cleaned_actions[] = $integration_action;
648 }
649 continue;
650 }
651
652 // Default.
653 $cleaned_actions[] = $integration_action;
654 }
655
656 // Overwrite.
657 $integration['actions'] = $cleaned_actions;
658 $cleaned_integrations[] = $integration;
659 }
660
661 return $cleaned_integrations;
662 }
663
664 /**
665 * Render the Integrations admin page.
666 */
667 public function render_integrations_page() {
668 $integrations = $this->integrations;
669 $integrations = $this->filter_integration_actions( $integrations );
670
671 // Integrations styles.
672 // wp_enqueue_style( 'wp-subs-integration-settings', SUBSCRPT_ASSETS . '/css/integration_settings.css', [], SUBSCRPT_VERSION, 'all' );
673
674 $menu = new \SpringDevs\Subscription\Admin\Menu();
675 $menu->render_admin_header( __( 'Integrations', 'subscription' ) );
676 include 'views/integrations.php';
677 $menu->render_admin_footer();
678 }
679 }
680