PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.4.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.4.0
2.4.0 2.3.0 2.2.0 2.1.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 All 65 releases
← All changes | includes/Admin/Integrations.php +477 -38 1.9.5 → 2.4.0 View file →
@@ -29,13 +29,13 @@
29 29
30 30 // Admin menu (sidebar).
31 31 add_action( 'admin_menu', array( $this, 'register_admin_menu' ), 20 );
32 32
33 - // WP Subscription navbar.
33 + // WPSubscription navbar.
34 34 add_filter( 'subscrpt_admin_header_menu_items', [ $this, 'add_integrations_menu_item' ], 10, 2 );
35 35
36 36 // Enqueue integrations scripts.
37 - // add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_integrations_scripts' ] );
37 + add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_integrations_scripts' ] );
38 38
39 39 // Integrations AJAX handler.
40 40 // add_action( 'admin_ajax_integrations_handler', [ $this,'integrations_handler_callback' ] );
41 41 // add_action( 'admin_ajax_nopriv_integrations_handler', [ $this,'integrations_handler_callback' ] );
@@ -62,14 +62,13 @@
62 62 __( 'Integrations', 'subscription' ),
63 63 'manage_options',
64 64 'wp-subscription-integrations',
65 65 [ $this, 'render_integrations_page' ],
66 - 40
67 66 );
68 67 }
69 68
70 69 /**
71 - * Add Integrations link to the WP Subscription admin header menu.
70 + * Add Integrations link to the WPSubscription admin header menu.
72 71 *
73 72 * @param array $menu_items Array of menu items.
74 73 * @param string $current Current active menu item slug.
75 74 */
@@ -85,18 +84,28 @@
85 84 /**
86 85 * Enqueue scripts for integrations page.
87 86 */
88 87 public function enqueue_integrations_scripts() {
89 - wp_enqueue_script( 'wp-subs-integrations', SUBSCRPT_ASSETS . '/js/integration_settings.js', [ 'jquery' ], SUBSCRPT_VERSION, true );
88 + $screen = get_current_screen();
89 + if ( ! $screen || false === strpos( $screen->id, 'wp-subscription-integrations' ) ) {
90 + return;
91 + }
90 92
93 + wp_enqueue_script( 'subscrpt-integrations', SUBSCRPT_ASSETS . '/js/integration_settings.js', [ 'wp-i18n' ], SUBSCRPT_VERSION, true );
94 + wp_set_script_translations( 'subscrpt-integrations', 'subscription', SUBSCRPT_PATH . '/languages' );
95 +
91 96 wp_localize_script(
92 - 'wp-subs-integrations',
93 - 'wpSubsIntegrations',
97 + 'subscrpt-integrations',
98 + 'subscrptIntegrations',
94 99 array(
95 - 'nonce' => wp_create_nonce( 'wp_subs_integrations_nonce' ),
96 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
100 + 'nonce' => wp_create_nonce( 'subscrpt_integration_install_nonce' ),
101 + 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
97 102 )
98 103 );
104 +
105 + // Browser-side filter rail. Enqueued on this hook, not in the render
106 + // callback, so it always loads.
107 + wp_enqueue_script( 'subscrpt-integrations-filter', SUBSCRPT_ASSETS . '/js/admin/integrations-filter.js', [], SUBSCRPT_VERSION, true );
99 108 }
100 109
101 110 /**
102 111 * Handle AJAX request for integrations.
@@ -184,8 +193,55 @@
184 193 return is_plugin_active( $plugin_file );
185 194 }
186 195
187 196 /**
197 + * Find the basename of an installed plugin from its wp.org slug.
198 + *
199 + * @param string $slug The wp.org plugin slug, which is also its directory.
200 + * @return string The plugin basename, or an empty string when not installed.
201 + */
202 + protected function find_plugin_file( $slug ) {
203 + if ( ! function_exists( 'get_plugins' ) ) {
204 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
205 + }
206 + foreach ( array_keys( get_plugins() ) as $plugin_file ) {
207 + if ( 0 === strpos( $plugin_file, $slug . '/' ) ) {
208 + return $plugin_file;
209 + }
210 + }
211 + return '';
212 + }
213 +
214 + /**
215 + * Mark a gateway card installed when its plugin is on disk, and give it an
216 + * Activate action for when that plugin is inactive.
217 + *
218 + * Gateway cards otherwise detect installation by a class the plugin declares,
219 + * which only exists while it is active, so an installed-but-inactive gateway
220 + * offered "Install Now" and the install failed on the existing folder.
221 + *
222 + * @param array $integration The integration card.
223 + * @param string $slug The wp.org plugin slug.
224 + * @return array
225 + */
226 + protected function with_gateway_plugin_state( array $integration, $slug ) {
227 + $plugin_file = $this->find_plugin_file( $slug );
228 + if ( '' === $plugin_file ) {
229 + return $integration;
230 + }
231 +
232 + $integration['is_installed'] = true;
233 + $integration['plugin_file'] = $plugin_file;
234 + $integration['actions'][] = [
235 + 'action' => 'activate',
236 + 'label' => __( 'Activate', 'subscription' ),
237 + 'type' => 'function',
238 + 'function' => "subscrptActivatePlugin(this, '" . esc_js( $plugin_file ) . "')",
239 + ];
240 + return $integration;
241 + }
242 +
243 + /**
188 244 * Check if a payment gateway is enabled.
189 245 *
190 246 * @param string $gateway_id Gateway ID.
191 247 */
@@ -200,12 +256,13 @@
200 256 * @return array
201 257 */
202 258 protected function get_integrations(): array {
203 259 $integrations = [
204 - [
205 - 'title' => 'PayPal for WP Subscription',
206 - 'description' => 'Accept subscription payments via PayPal.',
207 - 'icon_url' => SUBSCRPT_ASSETS . '/images/paypal.svg',
260 + 'paypal' => [
261 + 'title' => 'PayPal',
262 + 'description' => __( 'Accept recurring subscription payments directly through PayPal.', 'subscription' ),
263 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/paypal.svg',
264 + 'type' => 'payment_gateway',
208 265 'is_installed' => 'on' === get_option( 'wp_subs_paypal_integration_enabled', 'off' ),
209 266 'is_active' => self::is_gateway_enabled( 'wp_subscription_paypal' ),
210 267 'supports_recurring' => true,
211 268 'actions' => [
@@ -216,9 +273,9 @@
216 273 // 'function' => 'wpSubsInstallPaypalIntegration()',
217 274 // ],
218 275 [
219 276 'action' => 'settings',
220 - 'label' => 'Settings',
277 + 'label' => __( 'Settings', 'subscription' ),
221 278 'type' => 'link',
222 279 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wp_subscription_paypal' ),
223 280 ],
224 281 // [
@@ -229,34 +286,36 @@
229 286 // 'class' => 'button button-primary wp-subs-button-danger',
230 287 // ],
231 288 ],
232 289 ],
233 - [
290 + 'stripe' => [
234 291 'title' => 'Stripe',
235 - 'description' => 'Process subscription payments securely with Stripe.',
236 - 'icon_url' => 'https://ps.w.org/woocommerce-gateway-stripe/assets/icon-256x256.png',
292 + 'description' => __( 'Process subscription payments securely with Stripe.', 'subscription' ),
293 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/stripe.png',
294 + 'type' => 'payment_gateway',
237 295 'is_installed' => class_exists( 'WC_Stripe' ),
238 296 'is_active' => self::is_gateway_enabled( 'stripe' ),
239 297 'supports_recurring' => true,
240 298 'actions' => [
241 299 [
242 - 'action' => 'install',
243 - 'label' => 'Install Now',
244 - 'type' => 'link',
245 - 'url' => admin_url( 'plugin-install.php?s=WooCommerce%2520Stripe%2520Payment%2520Gateway&tab=search&type=term' ),
300 + 'action' => 'install',
301 + 'label' => __( 'Install Now', 'subscription' ),
302 + 'type' => 'function',
303 + 'function' => "subscrptInstallPlugin(this, 'woocommerce-gateway-stripe')",
246 304 ],
247 305 [
248 306 'action' => 'settings',
249 - 'label' => 'Settings',
307 + 'label' => __( 'Settings', 'subscription' ),
250 308 'type' => 'link',
251 309 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe&panel=settings' ),
252 310 ],
253 311 ],
254 312 ],
255 - [
313 + 'paddle' => [
256 314 'title' => 'Paddle',
257 - 'description' => 'Process subscription payments securely with Paddle.',
258 - 'icon_url' => SUBSCRPT_ASSETS . '/images/paddle.svg',
315 + 'description' => __( 'Process subscription payments securely with Paddle.', 'subscription' ),
316 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/paddle.svg',
317 + 'type' => 'payment_gateway',
259 318 'is_installed' => class_exists( 'SmartPayWoo\Gateways\Paddle\SmartPay_Paddle' ),
260 319 'is_active' => self::is_gateway_enabled( 'smartpay_paddle' ),
261 320 'supports_recurring' => true,
262 321 'actions' => [
@@ -261,15 +320,15 @@
261 320 'supports_recurring' => true,
262 321 'actions' => [
263 322 [
264 323 'action' => 'install',
265 - 'label' => 'Install Now',
266 - 'type' => 'link',
267 - 'url' => admin_url( 'plugin-install.php?s=WooCommerce%2520Stripe%2520Payment%2520Gateway&tab=search&type=term' ),
324 + 'label' => __( 'Get Paddle', 'subscription' ),
325 + 'type' => 'external_link',
326 + 'url' => 'https://wpsmartpay.com/paddle-for-woocommerce/',
268 327 ],
269 328 [
270 329 'action' => 'enable',
271 - 'label' => 'Enable Gateway',
330 + 'label' => __( 'Enable Gateway', 'subscription' ),
272 331 'type' => 'toggle_option',
273 332 'option_key' => 'woocommerce_enable_paddle_gateway',
274 333 'value' => true,
275 334 ],
@@ -274,21 +333,386 @@
274 333 'value' => true,
275 334 ],
276 335 [
277 336 'action' => 'settings',
278 - 'label' => 'Settings',
337 + 'label' => __( 'Settings', 'subscription' ),
279 338 'type' => 'link',
280 339 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=smartpay_paddle&from=WCADMIN_PAYMENT_SETTINGS' ),
281 340 ],
282 341 [
283 - 'label' => 'More Details',
342 + 'label' => __( 'More Details', 'subscription' ),
284 343 'type' => 'external_link',
285 344 'url' => 'https://wpsmartpay.com/paddle-for-woocommerce/',
286 345 ],
287 346 ],
288 347 ],
348 + 'mollie' => [
349 + 'title' => 'Mollie',
350 + 'description' => __( 'Pay for subscriptions with Mollie Payments for WooCommerce.', 'subscription' ),
351 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/mollie.png',
352 + 'type' => 'payment_gateway',
353 + 'is_pro' => true,
354 + 'is_installed' => class_exists( 'Mollie\WooCommerce\Activation\ActivationModule' ),
355 + 'is_active' => self::is_gateway_enabled( 'mollie_wc_gateway', true ),
356 + 'supports_recurring' => true,
357 + 'actions' => [
358 + [
359 + 'action' => 'install',
360 + 'label' => __( 'Install Now', 'subscription' ),
361 + 'type' => 'function',
362 + 'function' => "subscrptInstallPlugin(this, 'mollie-payments-for-woocommerce')",
363 + ],
364 + [
365 + 'action' => 'settings',
366 + 'label' => __( 'Settings', 'subscription' ),
367 + 'type' => 'link',
368 + 'url' => admin_url( 'admin.php?page=wc-settings&tab=mollie_settings' ),
369 + ],
370 + [
371 + 'label' => __( 'More Details', 'subscription' ),
372 + 'type' => 'external_link',
373 + 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-payment-with-mollie?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
374 + ],
375 + ],
376 + ],
377 + 'razorpay' => [
378 + 'title' => 'Razorpay',
379 + 'description' => __( 'Pay for subscriptions securely with Razorpay for WooCommerce.', 'subscription' ),
380 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/razorpay.png',
381 + 'type' => 'payment_gateway',
382 + 'is_pro' => true,
383 + 'is_beta' => true,
384 + 'is_installed' => class_exists( 'WC_Razorpay' ),
385 + 'is_active' => self::is_gateway_enabled( 'razorpay' ),
386 + 'supports_recurring' => true,
387 + 'actions' => [
388 + [
389 + 'action' => 'install',
390 + 'label' => __( 'Install Now', 'subscription' ),
391 + 'type' => 'function',
392 + 'function' => "subscrptInstallPlugin(this, 'woo-razorpay')",
393 + ],
394 + [
395 + 'action' => 'settings',
396 + 'label' => __( 'Settings', 'subscription' ),
397 + 'type' => 'link',
398 + 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=razorpay' ),
399 + ],
400 + [
401 + 'label' => __( 'More Details', 'subscription' ),
402 + 'type' => 'external_link',
403 + 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-payment-with-razorpay?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
404 + ],
405 + ],
406 + ],
407 + 'xendit' => [
408 + 'title' => 'Xendit',
409 + 'description' => __( 'Pay for subscriptions securely with Xendit for WooCommerce.', 'subscription' ),
410 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/xendit.png',
411 + 'type' => 'payment_gateway',
412 + 'is_pro' => true,
413 + 'is_beta' => true,
414 + 'is_installed' => class_exists( 'WC_Xendit_CC' ),
415 + 'is_active' => self::is_gateway_enabled( 'xendit' ),
416 + 'supports_recurring' => true,
417 + 'actions' => [
418 + [
419 + 'action' => 'install',
420 + 'label' => __( 'Install Now', 'subscription' ),
421 + 'type' => 'function',
422 + 'function' => "subscrptInstallPlugin(this, 'woo-xendit-virtual-accounts')",
423 + ],
424 + [
425 + 'action' => 'settings',
426 + 'label' => __( 'Settings', 'subscription' ),
427 + 'type' => 'link',
428 + 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=xendit_gateway' ),
429 + ],
430 + [
431 + 'label' => __( 'More Details', 'subscription' ),
432 + 'type' => 'external_link',
433 + 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-payment-with-xendit?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
434 + ],
435 + ],
436 + ],
289 437 ];
290 438
439 + $integrations['stripe'] = $this->with_gateway_plugin_state( $integrations['stripe'], 'woocommerce-gateway-stripe' );
440 + $integrations['mollie'] = $this->with_gateway_plugin_state( $integrations['mollie'], 'mollie-payments-for-woocommerce' );
441 + $integrations['razorpay'] = $this->with_gateway_plugin_state( $integrations['razorpay'], 'woo-razorpay' );
442 + $integrations['xendit'] = $this->with_gateway_plugin_state( $integrations['xendit'], 'woo-xendit-virtual-accounts' );
443 +
444 + // Third-party integrations (requires Pro plugin to function).
445 + $third_party = [
446 + // LMS.
447 + 'tutor_lms' => [
448 + 'title' => 'Tutor LMS',
449 + 'description' => __( 'Restrict course access based on subscription status. Enroll and unenroll students automatically.', 'subscription' ),
450 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/tutor-lms.jpeg',
451 + 'type' => 'third_party',
452 + 'is_pro' => true,
453 + 'category' => 'lms',
454 + 'is_installed' => $this->is_plugin_installed( 'tutor/tutor.php' ),
455 + 'is_active' => is_plugin_active( 'tutor/tutor.php' ) && class_exists( 'TUTOR\Tutor' ),
456 + 'actions' => [
457 + [
458 + 'action' => 'install',
459 + 'label' => __( 'Install Now', 'subscription' ),
460 + 'type' => 'function',
461 + 'function' => "subscrptInstallPlugin(this, 'tutor')",
462 + ],
463 + [
464 + 'action' => 'activate',
465 + 'label' => __( 'Activate', 'subscription' ),
466 + 'type' => 'function',
467 + 'function' => "subscrptActivatePlugin(this, 'tutor/tutor.php')",
468 + ],
469 + [
470 + 'label' => __( 'Learn More', 'subscription' ),
471 + 'type' => 'external_link',
472 + 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-tutor-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
473 + ],
474 + ],
475 + ],
476 + 'learnpress' => [
477 + 'title' => 'LearnPress',
478 + 'description' => __( 'Connect subscriptions with LearnPress courses. Enroll users automatically when subscriptions are active.', 'subscription' ),
479 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/learnpress.png',
480 + 'type' => 'third_party',
481 + 'is_pro' => true,
482 + 'category' => 'lms',
483 + 'is_installed' => $this->is_plugin_installed( 'learnpress/learnpress.php' ),
484 + 'is_active' => is_plugin_active( 'learnpress/learnpress.php' ) && class_exists( 'LearnPress' ),
485 + 'actions' => [
486 + [
487 + 'action' => 'install',
488 + 'label' => __( 'Install Now', 'subscription' ),
489 + 'type' => 'function',
490 + 'function' => "subscrptInstallPlugin(this, 'learnpress')",
491 + ],
492 + [
493 + 'action' => 'activate',
494 + 'label' => __( 'Activate', 'subscription' ),
495 + 'type' => 'function',
496 + 'function' => "subscrptActivatePlugin(this, 'learnpress/learnpress.php')",
497 + ],
498 + [
499 + 'label' => __( 'Learn More', 'subscription' ),
500 + 'type' => 'external_link',
501 + 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-learnpress-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
502 + ],
503 + ],
504 + ],
505 + 'learndash' => [
506 + 'title' => 'LearnDash',
507 + 'description' => __( 'Sync subscription status with LearnDash group enrollment and course access.', 'subscription' ),
508 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/learndash.jpeg',
509 + 'type' => 'third_party',
510 + 'is_pro' => true,
511 + 'category' => 'lms',
512 + 'is_installed' => $this->is_plugin_installed( 'sfwd-lms/sfwd_lms.php' ),
513 + 'is_active' => is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) && class_exists( 'LearnDash\Core\App' ),
514 + 'actions' => [
515 + [
516 + 'action' => 'install',
517 + 'label' => __( 'Get LearnDash', 'subscription' ),
518 + 'type' => 'external_link',
519 + 'url' => 'https://www.learndash.com/',
520 + ],
521 + [
522 + 'action' => 'activate',
523 + 'label' => __( 'Activate', 'subscription' ),
524 + 'type' => 'function',
525 + 'function' => "subscrptActivatePlugin(this, 'sfwd-lms/sfwd_lms.php')",
526 + ],
527 + [
528 + 'label' => __( 'Learn More', 'subscription' ),
529 + 'type' => 'external_link',
530 + 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-learndash-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
531 + ],
532 + ],
533 + ],
534 + // CRM.
535 + 'fluentcrm' => [
536 + 'title' => 'FluentCRM',
537 + 'description' => __( 'Trigger email sequences and manage contacts based on subscription events and status changes.', 'subscription' ),
538 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/fluentcrm.png',
539 + 'type' => 'third_party',
540 + 'is_pro' => true,
541 + 'category' => 'crm',
542 + 'is_installed' => $this->is_plugin_installed( 'fluent-crm/fluent-crm.php' ),
543 + 'is_active' => class_exists( 'FluentCrm\App\Services\Funnel\BaseTrigger' ),
544 + 'actions' => [
545 + [
546 + 'action' => 'install',
547 + 'label' => __( 'Install Now', 'subscription' ),
548 + 'type' => 'function',
549 + 'function' => "subscrptInstallPlugin(this, 'fluent-crm')",
550 + ],
551 + [
552 + 'action' => 'activate',
553 + 'label' => __( 'Activate', 'subscription' ),
554 + 'type' => 'function',
555 + 'function' => "subscrptActivatePlugin(this, 'fluent-crm/fluent-crm.php')",
556 + ],
557 + [
558 + 'label' => __( 'Learn More', 'subscription' ),
559 + 'type' => 'external_link',
560 + 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-fluent-crm?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
561 + ],
562 + ],
563 + ],
564 + // Automation.
565 + 'automatorwp' => [
566 + 'title' => 'AutomatorWP',
567 + 'description' => __( 'Build powerful automations triggered by subscription events without writing any code.', 'subscription' ),
568 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/automatorwp.png',
569 + 'type' => 'third_party',
570 + 'is_pro' => true,
571 + 'category' => 'automation',
572 + 'is_installed' => $this->is_plugin_installed( 'automatorwp/automatorwp.php' ),
573 + 'is_active' => is_plugin_active( 'automatorwp/automatorwp.php' ) && class_exists( 'AutomatorWP' ),
574 + 'actions' => [
575 + [
576 + 'action' => 'install',
577 + 'label' => __( 'Install Now', 'subscription' ),
578 + 'type' => 'function',
579 + 'function' => "subscrptInstallPlugin(this, 'automatorwp')",
580 + ],
581 + [
582 + 'action' => 'activate',
583 + 'label' => __( 'Activate', 'subscription' ),
584 + 'type' => 'function',
585 + 'function' => "subscrptActivatePlugin(this, 'automatorwp/automatorwp.php')",
586 + ],
587 + // [
588 + // 'label' => __( 'Learn More', 'subscription' ),
589 + // 'type' => 'external_link',
590 + // 'url' => 'https://docs.wpsubscription.co/en/',
591 + // ],
592 + ],
593 + ],
594 + 'wpfusion' => [
595 + 'title' => 'WP Fusion',
596 + 'description' => __( 'Sync subscription data with your CRM and marketing platforms through WP Fusion.', 'subscription' ),
597 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/wp-fusion.png',
598 + 'type' => 'third_party',
599 + 'is_pro' => true,
600 + 'category' => 'automation',
601 + 'is_installed' => $this->is_plugin_installed( 'wp-fusion/wp-fusion.php' ) || class_exists( 'WPF_Integrations_Base' ),
602 + 'is_active' => class_exists( 'WPF_Integrations_Base' ),
603 + 'actions' => [
604 + [
605 + 'action' => 'install',
606 + 'label' => __( 'Get WP Fusion', 'subscription' ),
607 + 'type' => 'external_link',
608 + 'url' => 'https://wpfusion.com/',
609 + ],
610 + [
611 + 'action' => 'activate',
612 + 'label' => __( 'Activate', 'subscription' ),
613 + 'type' => 'function',
614 + 'function' => "subscrptActivatePlugin(this, 'wp-fusion/wp-fusion.php')",
615 + ],
616 + // [
617 + // 'label' => __( 'Learn More', 'subscription' ),
618 + // 'type' => 'external_link',
619 + // 'url' => 'https://docs.wpsubscription.co/en/',
620 + // ],
621 + ],
622 + ],
623 + // Email Marketing.
624 + 'mailpoet' => [
625 + 'title' => 'MailPoet',
626 + 'description' => __( 'Add subscribers to MailPoet lists and trigger email automations based on subscription lifecycle events.', 'subscription' ),
627 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/mailpoet.png',
628 + 'type' => 'third_party',
629 + 'is_pro' => true,
630 + 'category' => 'email',
631 + 'is_installed' => $this->is_plugin_installed( 'mailpoet/mailpoet.php' ) || is_plugin_active( 'mailpoet-premium/mailpoet-premium.php' ),
632 + 'is_active' => is_plugin_active( 'mailpoet/mailpoet.php' ) || is_plugin_active( 'mailpoet-premium/mailpoet-premium.php' ),
633 + 'actions' => [
634 + [
635 + 'action' => 'install',
636 + 'label' => __( 'Install Now', 'subscription' ),
637 + 'type' => 'function',
638 + 'function' => "subscrptInstallPlugin(this, 'mailpoet')",
639 + ],
640 + [
641 + 'action' => 'activate',
642 + 'label' => __( 'Activate', 'subscription' ),
643 + 'type' => 'function',
644 + 'function' => "subscrptActivatePlugin(this, 'mailpoet/mailpoet.php')",
645 + ],
646 + [
647 + 'label' => __( 'Learn More', 'subscription' ),
648 + 'type' => 'external_link',
649 + 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-mailpoet?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
650 + ],
651 + ],
652 + ],
653 + // License Management.
654 + 'wp_soft_lic' => [
655 + 'title' => 'WP Software License',
656 + 'description' => __( 'Issue and validate software licenses for subscription-based digital products.', 'subscription' ),
657 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/wp-software-license.png',
658 + 'type' => 'third_party',
659 + 'is_pro' => true,
660 + 'category' => 'license',
661 + 'is_installed' => $this->is_plugin_installed( 'software-license/software-license.php' ),
662 + 'is_active' => is_plugin_active( 'software-license/software-license.php' ) && class_exists( 'WOO_SL' ),
663 + 'actions' => [
664 + [
665 + 'action' => 'install',
666 + 'label' => __( 'Get Plugin', 'subscription' ),
667 + 'type' => 'external_link',
668 + 'url' => 'https://wpsoftwarelicense.com/',
669 + ],
670 + [
671 + 'action' => 'activate',
672 + 'label' => __( 'Activate', 'subscription' ),
673 + 'type' => 'function',
674 + 'function' => "subscrptActivatePlugin(this, 'software-license/software-license.php')",
675 + ],
676 + // [
677 + // 'label' => __( 'Learn More', 'subscription' ),
678 + // 'type' => 'external_link',
679 + // 'url' => 'https://docs.wpsubscription.co/en/',
680 + // ],
681 + ],
682 + ],
683 + 'license_mgr' => [
684 + 'title' => 'License Manager for WooCommerce',
685 + 'description' => __( 'Generate and manage software license keys that are automatically tied to active subscriptions.', 'subscription' ),
686 + 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/license-manager.png',
687 + 'type' => 'third_party',
688 + 'is_pro' => true,
689 + 'category' => 'license',
690 + 'is_installed' => $this->is_plugin_installed( 'license-manager-for-woocommerce/license-manager-for-woocommerce.php' ),
691 + 'is_active' => is_plugin_active( 'license-manager-for-woocommerce/license-manager-for-woocommerce.php' ) && class_exists( 'LicenseManagerForWooCommerce\Models\Resources\License' ),
692 + 'actions' => [
693 + [
694 + 'action' => 'install',
695 + 'label' => __( 'Install Now', 'subscription' ),
696 + 'type' => 'function',
697 + 'function' => "subscrptInstallPlugin(this, 'license-manager-for-woocommerce')",
698 + ],
699 + [
700 + 'action' => 'activate',
701 + 'label' => __( 'Activate', 'subscription' ),
702 + 'type' => 'function',
703 + 'function' => "subscrptActivatePlugin(this, 'license-manager-for-woocommerce/license-manager-for-woocommerce.php')",
704 + ],
705 + // [
706 + // 'label' => __( 'Learn More', 'subscription' ),
707 + // 'type' => 'external_link',
708 + // 'url' => 'https://docs.wpsubscription.co/en/',
709 + // ],
710 + ],
711 + ],
712 + ];
713 + $integrations = array_merge( $integrations, $third_party );
714 +
291 715 // Add more integrations as needed.
292 716 $integrations = apply_filters( 'wpsubs_integrations', $integrations );
293 717
294 718 return $integrations;
@@ -305,10 +729,16 @@
305 729 foreach ( $integrations as $integration ) {
306 730 $is_installed = $integration['is_installed'] ?? false;
307 731 $is_active = $integration['is_active'] ?? false;
308 732
309 - $cleaned_actions = [];
733 + // A gateway card is "active" when its gateway is enabled, which is not
734 + // the same as its plugin being active; read the plugin itself.
735 + $plugin_file = $integration['plugin_file'] ?? '';
736 + $plugin_active = '' !== $plugin_file ? is_plugin_active( $plugin_file ) : $is_active;
310 737
738 + $cleaned_actions = [];
739 + $shown_install_url = null;
740 +
311 741 foreach ( $integration['actions'] as $integration_action ) {
312 742 $action_tag = $integration_action['action'] ?? null;
313 743
314 744 if ( 'install' === $action_tag ) {
@@ -313,8 +743,9 @@
313 743
314 744 if ( 'install' === $action_tag ) {
315 745 if ( ! $is_installed ) {
316 746 $cleaned_actions[] = $integration_action;
747 + $shown_install_url = $integration_action['url'] ?? null;
317 748 }
318 749 continue;
319 750 }
320 751 if ( 'uninstall' === $action_tag ) {
@@ -322,8 +753,14 @@
322 753 $cleaned_actions[] = $integration_action;
323 754 }
324 755 continue;
325 756 }
757 + if ( 'activate' === $action_tag ) {
758 + if ( $is_installed && ! $plugin_active ) {
759 + $cleaned_actions[] = $integration_action;
760 + }
761 + continue;
762 + }
326 763 if ( 'enable' === $action_tag ) {
327 764 if ( $is_installed && ! $is_active ) {
328 765 $cleaned_actions[] = $integration_action;
329 766 }
@@ -329,15 +766,20 @@
329 766 }
330 767 continue;
331 768 }
332 769 if ( 'settings' === $action_tag ) {
333 - if ( $is_installed ) {
770 + if ( $is_installed && ( '' === $plugin_file || $plugin_active ) ) {
334 771 $cleaned_actions[] = $integration_action;
335 772 }
336 773 continue;
337 774 }
338 775
339 - // Default.
776 + // Default. Skip a "More Details"-style link that just repeats the
777 + // install/"Get X" link already shown (e.g. Paddle), so the card
778 + // does not carry the same URL twice.
779 + if ( null !== $shown_install_url && ( $integration_action['url'] ?? null ) === $shown_install_url ) {
780 + continue;
781 + }
340 782 $cleaned_actions[] = $integration_action;
341 783 }
342 784
343 785 // Overwrite.
@@ -354,13 +796,10 @@
354 796 public function render_integrations_page() {
355 797 $integrations = $this->integrations;
356 798 $integrations = $this->filter_integration_actions( $integrations );
357 799
358 - // Integrations styles.
359 - // wp_enqueue_style( 'wp-subs-integration-settings', SUBSCRPT_ASSETS . '/css/integration_settings.css', [], SUBSCRPT_VERSION, 'all' );
360 -
361 800 $menu = new \SpringDevs\Subscription\Admin\Menu();
362 - $menu->render_admin_header();
801 + $menu->render_admin_header( __( 'Integrations', 'subscription' ) );
363 802 include 'views/integrations.php';
364 803 $menu->render_admin_footer();
365 804 }
366 805 }