Onboarding.php
5 months ago
OnboardingHelper.php
1 year ago
OnboardingIndustries.php
2 years ago
OnboardingJetpack.php
3 years ago
OnboardingMailchimp.php
3 years ago
OnboardingProducts.php
3 years ago
OnboardingProfile.php
1 year ago
OnboardingSetupWizard.php
1 year ago
OnboardingSync.php
2 years ago
OnboardingJetpack.php
67 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Onboarding Jetpack |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Internal\Admin\Onboarding; |
| 7 | |
| 8 | /** |
| 9 | * Contains logic around Jetpack setup during onboarding. |
| 10 | */ |
| 11 | class OnboardingJetpack { |
| 12 | /** |
| 13 | * Class instance. |
| 14 | * |
| 15 | * @var OnboardingJetpack instance |
| 16 | */ |
| 17 | private static $instance = null; |
| 18 | |
| 19 | /** |
| 20 | * Get class instance. |
| 21 | */ |
| 22 | final public static function instance() { |
| 23 | if ( ! static::$instance ) { |
| 24 | static::$instance = new static(); |
| 25 | } |
| 26 | return static::$instance; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Init. |
| 31 | */ |
| 32 | public function init() { |
| 33 | add_action( 'woocommerce_admin_plugins_pre_activate', array( $this, 'activate_and_install_jetpack_ahead_of_wcpay' ) ); |
| 34 | add_action( 'woocommerce_admin_plugins_pre_install', array( $this, 'activate_and_install_jetpack_ahead_of_wcpay' ) ); |
| 35 | |
| 36 | // Always hook into Jetpack connection even if outside of admin. |
| 37 | add_action( 'jetpack_site_registered', array( $this, 'set_woocommerce_setup_jetpack_opted_in' ) ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Sets the woocommerce_setup_jetpack_opted_in to true when Jetpack connects to WPCOM. |
| 42 | */ |
| 43 | public function set_woocommerce_setup_jetpack_opted_in() { |
| 44 | update_option( 'woocommerce_setup_jetpack_opted_in', true ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Ensure that Jetpack gets installed and activated ahead of WooCommerce Payments |
| 49 | * if both are being installed/activated at the same time. |
| 50 | * |
| 51 | * See: https://github.com/Automattic/woocommerce-payments/issues/1663 |
| 52 | * See: https://github.com/Automattic/jetpack/issues/19624 |
| 53 | * |
| 54 | * @param array $plugins A list of plugins to install or activate. |
| 55 | * |
| 56 | * @return array |
| 57 | */ |
| 58 | public function activate_and_install_jetpack_ahead_of_wcpay( $plugins ) { |
| 59 | if ( in_array( 'jetpack', $plugins, true ) && in_array( 'woocommerce-payments', $plugins, true ) ) { |
| 60 | array_unshift( $plugins, 'jetpack' ); |
| 61 | $plugins = array_unique( $plugins ); |
| 62 | } |
| 63 | return $plugins; |
| 64 | } |
| 65 | |
| 66 | } |
| 67 |