| @@ -192,8 +192,55 @@ | ||
| 192 | 192 | return is_plugin_active( $plugin_file ); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | + * Find the basename of an installed plugin from its wp.org slug. | |
| 197 | + * | |
| 198 | + * @param string $slug The wp.org plugin slug, which is also its directory. | |
| 199 | + * @return string The plugin basename, or an empty string when not installed. | |
| 200 | + */ | |
| 201 | + protected function find_plugin_file( $slug ) { | |
| 202 | + if ( ! function_exists( 'get_plugins' ) ) { | |
| 203 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 204 | + } | |
| 205 | + foreach ( array_keys( get_plugins() ) as $plugin_file ) { | |
| 206 | + if ( 0 === strpos( $plugin_file, $slug . '/' ) ) { | |
| 207 | + return $plugin_file; | |
| 208 | + } | |
| 209 | + } | |
| 210 | + return ''; | |
| 211 | + } | |
| 212 | + | |
| 213 | + /** | |
| 214 | + * Mark a gateway card installed when its plugin is on disk, and give it an | |
| 215 | + * Activate action for when that plugin is inactive. | |
| 216 | + * | |
| 217 | + * Gateway cards otherwise detect installation by a class the plugin declares, | |
| 218 | + * which only exists while it is active, so an installed-but-inactive gateway | |
| 219 | + * offered "Install Now" and the install failed on the existing folder. | |
| 220 | + * | |
| 221 | + * @param array $integration The integration card. | |
| 222 | + * @param string $slug The wp.org plugin slug. | |
| 223 | + * @return array | |
| 224 | + */ | |
| 225 | + protected function with_gateway_plugin_state( array $integration, $slug ) { | |
| 226 | + $plugin_file = $this->find_plugin_file( $slug ); | |
| 227 | + if ( '' === $plugin_file ) { | |
| 228 | + return $integration; | |
| 229 | + } | |
| 230 | + | |
| 231 | + $integration['is_installed'] = true; | |
| 232 | + $integration['plugin_file'] = $plugin_file; | |
| 233 | + $integration['actions'][] = [ | |
| 234 | + 'action' => 'activate', | |
| 235 | + 'label' => __( 'Activate', 'subscription' ), | |
| 236 | + 'type' => 'function', | |
| 237 | + 'function' => "subscrptActivatePlugin(this, '" . esc_js( $plugin_file ) . "')", | |
| 238 | + ]; | |
| 239 | + return $integration; | |
| 240 | + } | |
| 241 | + | |
| 242 | + /** | |
| 196 | 243 | * Check if a payment gateway is enabled. |
| 197 | 244 | * |
| 198 | 245 | * @param string $gateway_id Gateway ID. |
| 199 | 246 | */ |
| @@ -387,8 +434,13 @@ | ||
| 387 | 434 | ], |
| 388 | 435 | ], |
| 389 | 436 | ]; |
| 390 | 437 | |
| 438 | + $integrations['stripe'] = $this->with_gateway_plugin_state( $integrations['stripe'], 'woocommerce-gateway-stripe' ); | |
| 439 | + $integrations['mollie'] = $this->with_gateway_plugin_state( $integrations['mollie'], 'mollie-payments-for-woocommerce' ); | |
| 440 | + $integrations['razorpay'] = $this->with_gateway_plugin_state( $integrations['razorpay'], 'woo-razorpay' ); | |
| 441 | + $integrations['xendit'] = $this->with_gateway_plugin_state( $integrations['xendit'], 'woo-xendit-virtual-accounts' ); | |
| 442 | + | |
| 391 | 443 | // Third-party integrations (requires Pro plugin to function). |
| 392 | 444 | $third_party = [ |
| 393 | 445 | // LMS. |
| 394 | 446 | 'tutor_lms' => [ |
| @@ -397,9 +449,9 @@ | ||
| 397 | 449 | 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/tutor-lms.jpeg', |
| 398 | 450 | 'type' => 'third_party', |
| 399 | 451 | 'is_pro' => true, |
| 400 | 452 | 'category' => 'lms', |
| 401 | - 'is_installed' => is_plugin_active( 'tutor/tutor.php' ) && class_exists( 'TUTOR\Tutor' ), | |
| 453 | + 'is_installed' => $this->is_plugin_installed( 'tutor/tutor.php' ), | |
| 402 | 454 | 'is_active' => is_plugin_active( 'tutor/tutor.php' ) && class_exists( 'TUTOR\Tutor' ), |
| 403 | 455 | 'actions' => [ |
| 404 | 456 | [ |
| 405 | 457 | 'action' => 'install', |
| @@ -407,8 +459,14 @@ | ||
| 407 | 459 | 'type' => 'function', |
| 408 | 460 | 'function' => "subscrptInstallPlugin(this, 'tutor')", |
| 409 | 461 | ], |
| 410 | 462 | [ |
| 463 | + 'action' => 'activate', | |
| 464 | + 'label' => __( 'Activate', 'subscription' ), | |
| 465 | + 'type' => 'function', | |
| 466 | + 'function' => "subscrptActivatePlugin(this, 'tutor/tutor.php')", | |
| 467 | + ], | |
| 468 | + [ | |
| 411 | 469 | 'label' => __( 'Learn More', 'subscription' ), |
| 412 | 470 | 'type' => 'external_link', |
| 413 | 471 | 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-tutor-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs', |
| 414 | 472 | ], |
| @@ -420,9 +478,9 @@ | ||
| 420 | 478 | 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/learnpress.png', |
| 421 | 479 | 'type' => 'third_party', |
| 422 | 480 | 'is_pro' => true, |
| 423 | 481 | 'category' => 'lms', |
| 424 | - 'is_installed' => is_plugin_active( 'learnpress/learnpress.php' ) && class_exists( 'LearnPress' ), | |
| 482 | + 'is_installed' => $this->is_plugin_installed( 'learnpress/learnpress.php' ), | |
| 425 | 483 | 'is_active' => is_plugin_active( 'learnpress/learnpress.php' ) && class_exists( 'LearnPress' ), |
| 426 | 484 | 'actions' => [ |
| 427 | 485 | [ |
| 428 | 486 | 'action' => 'install', |
| @@ -430,8 +488,14 @@ | ||
| 430 | 488 | 'type' => 'function', |
| 431 | 489 | 'function' => "subscrptInstallPlugin(this, 'learnpress')", |
| 432 | 490 | ], |
| 433 | 491 | [ |
| 492 | + 'action' => 'activate', | |
| 493 | + 'label' => __( 'Activate', 'subscription' ), | |
| 494 | + 'type' => 'function', | |
| 495 | + 'function' => "subscrptActivatePlugin(this, 'learnpress/learnpress.php')", | |
| 496 | + ], | |
| 497 | + [ | |
| 434 | 498 | 'label' => __( 'Learn More', 'subscription' ), |
| 435 | 499 | 'type' => 'external_link', |
| 436 | 500 | 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-learnpress-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs', |
| 437 | 501 | ], |
| @@ -443,9 +507,9 @@ | ||
| 443 | 507 | 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/learndash.jpeg', |
| 444 | 508 | 'type' => 'third_party', |
| 445 | 509 | 'is_pro' => true, |
| 446 | 510 | 'category' => 'lms', |
| 447 | - 'is_installed' => is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) && class_exists( 'LearnDash\Core\App' ), | |
| 511 | + 'is_installed' => $this->is_plugin_installed( 'sfwd-lms/sfwd_lms.php' ), | |
| 448 | 512 | 'is_active' => is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) && class_exists( 'LearnDash\Core\App' ), |
| 449 | 513 | 'actions' => [ |
| 450 | 514 | [ |
| 451 | 515 | 'action' => 'install', |
| @@ -453,8 +517,14 @@ | ||
| 453 | 517 | 'type' => 'external_link', |
| 454 | 518 | 'url' => 'https://www.learndash.com/', |
| 455 | 519 | ], |
| 456 | 520 | [ |
| 521 | + 'action' => 'activate', | |
| 522 | + 'label' => __( 'Activate', 'subscription' ), | |
| 523 | + 'type' => 'function', | |
| 524 | + 'function' => "subscrptActivatePlugin(this, 'sfwd-lms/sfwd_lms.php')", | |
| 525 | + ], | |
| 526 | + [ | |
| 457 | 527 | 'label' => __( 'Learn More', 'subscription' ), |
| 458 | 528 | 'type' => 'external_link', |
| 459 | 529 | 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-learndash-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs', |
| 460 | 530 | ], |
| @@ -467,9 +537,9 @@ | ||
| 467 | 537 | 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/fluentcrm.png', |
| 468 | 538 | 'type' => 'third_party', |
| 469 | 539 | 'is_pro' => true, |
| 470 | 540 | 'category' => 'crm', |
| 471 | - 'is_installed' => class_exists( 'FluentCrm\App\Services\Funnel\BaseTrigger' ), | |
| 541 | + 'is_installed' => $this->is_plugin_installed( 'fluent-crm/fluent-crm.php' ), | |
| 472 | 542 | 'is_active' => class_exists( 'FluentCrm\App\Services\Funnel\BaseTrigger' ), |
| 473 | 543 | 'actions' => [ |
| 474 | 544 | [ |
| 475 | 545 | 'action' => 'install', |
| @@ -477,8 +547,14 @@ | ||
| 477 | 547 | 'type' => 'function', |
| 478 | 548 | 'function' => "subscrptInstallPlugin(this, 'fluent-crm')", |
| 479 | 549 | ], |
| 480 | 550 | [ |
| 551 | + 'action' => 'activate', | |
| 552 | + 'label' => __( 'Activate', 'subscription' ), | |
| 553 | + 'type' => 'function', | |
| 554 | + 'function' => "subscrptActivatePlugin(this, 'fluent-crm/fluent-crm.php')", | |
| 555 | + ], | |
| 556 | + [ | |
| 481 | 557 | 'label' => __( 'Learn More', 'subscription' ), |
| 482 | 558 | 'type' => 'external_link', |
| 483 | 559 | 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-fluent-crm?utm_source=plugin&utm_medium=admin&utm_campaign=docs', |
| 484 | 560 | ], |
| @@ -491,9 +567,9 @@ | ||
| 491 | 567 | 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/automatorwp.png', |
| 492 | 568 | 'type' => 'third_party', |
| 493 | 569 | 'is_pro' => true, |
| 494 | 570 | 'category' => 'automation', |
| 495 | - 'is_installed' => is_plugin_active( 'automatorwp/automatorwp.php' ) && class_exists( 'AutomatorWP' ), | |
| 571 | + 'is_installed' => $this->is_plugin_installed( 'automatorwp/automatorwp.php' ), | |
| 496 | 572 | 'is_active' => is_plugin_active( 'automatorwp/automatorwp.php' ) && class_exists( 'AutomatorWP' ), |
| 497 | 573 | 'actions' => [ |
| 498 | 574 | [ |
| 499 | 575 | 'action' => 'install', |
| @@ -500,8 +576,14 @@ | ||
| 500 | 576 | 'label' => __( 'Install Now', 'subscription' ), |
| 501 | 577 | 'type' => 'function', |
| 502 | 578 | 'function' => "subscrptInstallPlugin(this, 'automatorwp')", |
| 503 | 579 | ], |
| 580 | + [ | |
| 581 | + 'action' => 'activate', | |
| 582 | + 'label' => __( 'Activate', 'subscription' ), | |
| 583 | + 'type' => 'function', | |
| 584 | + 'function' => "subscrptActivatePlugin(this, 'automatorwp/automatorwp.php')", | |
| 585 | + ], | |
| 504 | 586 | // [ |
| 505 | 587 | // 'label' => __( 'Learn More', 'subscription' ), |
| 506 | 588 | // 'type' => 'external_link', |
| 507 | 589 | // 'url' => 'https://docs.wpsubscription.co/en/', |
| @@ -514,9 +596,9 @@ | ||
| 514 | 596 | 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/wp-fusion.png', |
| 515 | 597 | 'type' => 'third_party', |
| 516 | 598 | 'is_pro' => true, |
| 517 | 599 | 'category' => 'automation', |
| 518 | - 'is_installed' => class_exists( 'WPF_Integrations_Base' ), | |
| 600 | + 'is_installed' => $this->is_plugin_installed( 'wp-fusion/wp-fusion.php' ) || class_exists( 'WPF_Integrations_Base' ), | |
| 519 | 601 | 'is_active' => class_exists( 'WPF_Integrations_Base' ), |
| 520 | 602 | 'actions' => [ |
| 521 | 603 | [ |
| 522 | 604 | 'action' => 'install', |
| @@ -523,8 +605,14 @@ | ||
| 523 | 605 | 'label' => __( 'Get WP Fusion', 'subscription' ), |
| 524 | 606 | 'type' => 'external_link', |
| 525 | 607 | 'url' => 'https://wpfusion.com/', |
| 526 | 608 | ], |
| 609 | + [ | |
| 610 | + 'action' => 'activate', | |
| 611 | + 'label' => __( 'Activate', 'subscription' ), | |
| 612 | + 'type' => 'function', | |
| 613 | + 'function' => "subscrptActivatePlugin(this, 'wp-fusion/wp-fusion.php')", | |
| 614 | + ], | |
| 527 | 615 | // [ |
| 528 | 616 | // 'label' => __( 'Learn More', 'subscription' ), |
| 529 | 617 | // 'type' => 'external_link', |
| 530 | 618 | // 'url' => 'https://docs.wpsubscription.co/en/', |
| @@ -538,9 +626,9 @@ | ||
| 538 | 626 | 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/mailpoet.png', |
| 539 | 627 | 'type' => 'third_party', |
| 540 | 628 | 'is_pro' => true, |
| 541 | 629 | 'category' => 'email', |
| 542 | - 'is_installed' => is_plugin_active( 'mailpoet/mailpoet.php' ) || is_plugin_active( 'mailpoet-premium/mailpoet-premium.php' ), | |
| 630 | + 'is_installed' => $this->is_plugin_installed( 'mailpoet/mailpoet.php' ) || is_plugin_active( 'mailpoet-premium/mailpoet-premium.php' ), | |
| 543 | 631 | 'is_active' => is_plugin_active( 'mailpoet/mailpoet.php' ) || is_plugin_active( 'mailpoet-premium/mailpoet-premium.php' ), |
| 544 | 632 | 'actions' => [ |
| 545 | 633 | [ |
| 546 | 634 | 'action' => 'install', |
| @@ -548,8 +636,14 @@ | ||
| 548 | 636 | 'type' => 'function', |
| 549 | 637 | 'function' => "subscrptInstallPlugin(this, 'mailpoet')", |
| 550 | 638 | ], |
| 551 | 639 | [ |
| 640 | + 'action' => 'activate', | |
| 641 | + 'label' => __( 'Activate', 'subscription' ), | |
| 642 | + 'type' => 'function', | |
| 643 | + 'function' => "subscrptActivatePlugin(this, 'mailpoet/mailpoet.php')", | |
| 644 | + ], | |
| 645 | + [ | |
| 552 | 646 | 'label' => __( 'Learn More', 'subscription' ), |
| 553 | 647 | 'type' => 'external_link', |
| 554 | 648 | 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-mailpoet?utm_source=plugin&utm_medium=admin&utm_campaign=docs', |
| 555 | 649 | ], |
| @@ -562,9 +656,9 @@ | ||
| 562 | 656 | 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/wp-software-license.png', |
| 563 | 657 | 'type' => 'third_party', |
| 564 | 658 | 'is_pro' => true, |
| 565 | 659 | 'category' => 'license', |
| 566 | - 'is_installed' => is_plugin_active( 'software-license/software-license.php' ) && class_exists( 'WOO_SL' ), | |
| 660 | + 'is_installed' => $this->is_plugin_installed( 'software-license/software-license.php' ), | |
| 567 | 661 | 'is_active' => is_plugin_active( 'software-license/software-license.php' ) && class_exists( 'WOO_SL' ), |
| 568 | 662 | 'actions' => [ |
| 569 | 663 | [ |
| 570 | 664 | 'action' => 'install', |
| @@ -571,8 +665,14 @@ | ||
| 571 | 665 | 'label' => __( 'Get Plugin', 'subscription' ), |
| 572 | 666 | 'type' => 'external_link', |
| 573 | 667 | 'url' => 'https://wpsoftwarelicense.com/', |
| 574 | 668 | ], |
| 669 | + [ | |
| 670 | + 'action' => 'activate', | |
| 671 | + 'label' => __( 'Activate', 'subscription' ), | |
| 672 | + 'type' => 'function', | |
| 673 | + 'function' => "subscrptActivatePlugin(this, 'software-license/software-license.php')", | |
| 674 | + ], | |
| 575 | 675 | // [ |
| 576 | 676 | // 'label' => __( 'Learn More', 'subscription' ), |
| 577 | 677 | // 'type' => 'external_link', |
| 578 | 678 | // 'url' => 'https://docs.wpsubscription.co/en/', |
| @@ -585,9 +685,9 @@ | ||
| 585 | 685 | 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/license-manager.png', |
| 586 | 686 | 'type' => 'third_party', |
| 587 | 687 | 'is_pro' => true, |
| 588 | 688 | 'category' => 'license', |
| 589 | - 'is_installed' => is_plugin_active( 'license-manager-for-woocommerce/license-manager-for-woocommerce.php' ) && class_exists( 'LicenseManagerForWooCommerce\Models\Resources\License' ), | |
| 689 | + 'is_installed' => $this->is_plugin_installed( 'license-manager-for-woocommerce/license-manager-for-woocommerce.php' ), | |
| 590 | 690 | 'is_active' => is_plugin_active( 'license-manager-for-woocommerce/license-manager-for-woocommerce.php' ) && class_exists( 'LicenseManagerForWooCommerce\Models\Resources\License' ), |
| 591 | 691 | 'actions' => [ |
| 592 | 692 | [ |
| 593 | 693 | 'action' => 'install', |
| @@ -594,8 +694,14 @@ | ||
| 594 | 694 | 'label' => __( 'Install Now', 'subscription' ), |
| 595 | 695 | 'type' => 'function', |
| 596 | 696 | 'function' => "subscrptInstallPlugin(this, 'license-manager-for-woocommerce')", |
| 597 | 697 | ], |
| 698 | + [ | |
| 699 | + 'action' => 'activate', | |
| 700 | + 'label' => __( 'Activate', 'subscription' ), | |
| 701 | + 'type' => 'function', | |
| 702 | + 'function' => "subscrptActivatePlugin(this, 'license-manager-for-woocommerce/license-manager-for-woocommerce.php')", | |
| 703 | + ], | |
| 598 | 704 | // [ |
| 599 | 705 | // 'label' => __( 'Learn More', 'subscription' ), |
| 600 | 706 | // 'type' => 'external_link', |
| 601 | 707 | // 'url' => 'https://docs.wpsubscription.co/en/', |
| @@ -622,8 +728,13 @@ | ||
| 622 | 728 | foreach ( $integrations as $integration ) { |
| 623 | 729 | $is_installed = $integration['is_installed'] ?? false; |
| 624 | 730 | $is_active = $integration['is_active'] ?? false; |
| 625 | 731 | |
| 732 | + // A gateway card is "active" when its gateway is enabled, which is not | |
| 733 | + // the same as its plugin being active; read the plugin itself. | |
| 734 | + $plugin_file = $integration['plugin_file'] ?? ''; | |
| 735 | + $plugin_active = '' !== $plugin_file ? is_plugin_active( $plugin_file ) : $is_active; | |
| 736 | + | |
| 626 | 737 | $cleaned_actions = []; |
| 627 | 738 | $shown_install_url = null; |
| 628 | 739 | |
| 629 | 740 | foreach ( $integration['actions'] as $integration_action ) { |
| @@ -641,8 +752,14 @@ | ||
| 641 | 752 | $cleaned_actions[] = $integration_action; |
| 642 | 753 | } |
| 643 | 754 | continue; |
| 644 | 755 | } |
| 756 | + if ( 'activate' === $action_tag ) { | |
| 757 | + if ( $is_installed && ! $plugin_active ) { | |
| 758 | + $cleaned_actions[] = $integration_action; | |
| 759 | + } | |
| 760 | + continue; | |
| 761 | + } | |
| 645 | 762 | if ( 'enable' === $action_tag ) { |
| 646 | 763 | if ( $is_installed && ! $is_active ) { |
| 647 | 764 | $cleaned_actions[] = $integration_action; |
| 648 | 765 | } |
| @@ -648,9 +765,9 @@ | ||
| 648 | 765 | } |
| 649 | 766 | continue; |
| 650 | 767 | } |
| 651 | 768 | if ( 'settings' === $action_tag ) { |
| 652 | - if ( $is_installed ) { | |
| 769 | + if ( $is_installed && ( '' === $plugin_file || $plugin_active ) ) { | |
| 653 | 770 | $cleaned_actions[] = $integration_action; |
| 654 | 771 | } |
| 655 | 772 | continue; |
| 656 | 773 | } |