PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.0.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.0.0
2.0.0 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 All 61 releases
subscription / includes / Admin / Integrations.php

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

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