From fbcc65034f78aba45439912d57fc2db467eadd97 Mon Sep 17 00:00:00 2001 From: MILLER/F Date: Thu, 17 Dec 2020 20:49:18 +0100 Subject: [PATCH] Allow setting Jetpack connection when JETPACK_MASTER_USER isn't available (https://github.com/woocommerce/woocommerce-admin/pull/5880) * Allow setting Jetpack connection when JETPACK_MASTER_USER isn't available * Fix linting * Fix lint * Update OnboardingSetUpShipping.php Added filter description --- .../src/Features/OnboardingSetUpShipping.php | 14 ++++++++++++-- .../src/Features/ShippingLabelBanner.php | 9 +++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/woocommerce-admin/src/Features/OnboardingSetUpShipping.php b/plugins/woocommerce-admin/src/Features/OnboardingSetUpShipping.php index 10f3d794ad9..048e5c67e2d 100644 --- a/plugins/woocommerce-admin/src/Features/OnboardingSetUpShipping.php +++ b/plugins/woocommerce-admin/src/Features/OnboardingSetUpShipping.php @@ -63,8 +63,18 @@ class OnboardingSetUpShipping { return; } - $user_token = \Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); - $jetpack_connected = isset( $user_token->external_user_id ); + if ( defined( 'JETPACK_MASTER_USER' ) ) { + $user_token = \Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); + $jetpack_connected = isset( $user_token->external_user_id ); + } else { + /** + * Filter allowing to set the status of the jetpack connection wiuthout setting constant `JETPACK_MASTER_USER` + * + * @param bool $is_connected False. + */ + $jetpack_connected = apply_filters( 'woocommerce_admin_is_jetpack_connected', false ); + } + $wcs_version = \WC_Connect_Loader::get_wcs_version(); $wcs_tos_accepted = \WC_Connect_Options::get_option( 'tos_accepted' ); diff --git a/plugins/woocommerce-admin/src/Features/ShippingLabelBanner.php b/plugins/woocommerce-admin/src/Features/ShippingLabelBanner.php index 19d1124c7e9..ee1b43267bf 100644 --- a/plugins/woocommerce-admin/src/Features/ShippingLabelBanner.php +++ b/plugins/woocommerce-admin/src/Features/ShippingLabelBanner.php @@ -59,9 +59,14 @@ class ShippingLabelBanner { $wcs_tos_accepted = null; if ( class_exists( '\Jetpack_Data' ) ) { - $user_token = \Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); - $jetpack_connected = isset( $user_token->external_user_id ); + if ( defined( 'JETPACK_MASTER_USER' ) ) { + $user_token = \Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); + $jetpack_connected = isset( $user_token->external_user_id ); + } else { + $jetpack_connected = apply_filters( 'woocommerce_admin_is_jetpack_connected', false ); + } + $jetpack_version = JETPACK__VERSION; }