Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove jetpack dependency #2439

Merged
merged 94 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
210c2bf
POC: remove jetpack dependency
frosso Jun 30, 2021
a903c8a
WIP
frosso Jun 30, 2021
c3ff595
WIP
frosso Jun 30, 2021
072b365
WIP
frosso Jun 30, 2021
d909cd9
older version to fix some little things
frosso Jun 30, 2021
a41901d
WIP
frosso Jun 30, 2021
ec39d7c
WIP
frosso Jun 30, 2021
20bfdc0
WIP
frosso Jun 30, 2021
3ccc8de
WIP
frosso Jun 30, 2021
d4dfb15
unused stuff
frosso Jun 30, 2021
68a61ee
WIP
frosso Jun 30, 2021
314db9c
all working, no touchy
frosso Jul 1, 2021
e17b5ee
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Jul 1, 2021
e5e377f
WIP
frosso Jul 1, 2021
97cffb2
WIP
frosso Jul 1, 2021
4aef84a
Update e2e_tests.yml
frosso Jul 1, 2021
9e94de0
Update e2e_tests.yml
frosso Jul 1, 2021
5d1026f
Update e2e_tests.yml
frosso Jul 1, 2021
d1234f3
WIP
frosso Jul 1, 2021
5293e86
Update e2e_tests.yml
frosso Jul 2, 2021
86a8356
WIP
frosso Jul 2, 2021
5ed5d2e
WIP
frosso Jul 2, 2021
09a23cc
diff cleanup
frosso Jul 2, 2021
be6de25
changelog entry
frosso Jul 2, 2021
6f4d648
add jetpack-tracking; remove JP version checks
frosso Jul 6, 2021
0070493
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Jul 6, 2021
e31fd4b
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Jul 7, 2021
0d9d56a
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Jul 8, 2021
36d9db8
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Jul 9, 2021
e8e7954
remove jetpack from docker image
frosso Jul 9, 2021
c13df7b
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Jul 13, 2021
e2d8df5
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Jul 14, 2021
44308be
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Jul 22, 2021
754737d
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Aug 4, 2021
0f2cd34
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Aug 12, 2021
7fdd3ee
Merge branch 'trunk' into frosso/jetpack-dependency-removal
frosso Aug 18, 2021
e6221c2
Update woocommerce-services.php
frosso Nov 25, 2022
2f7f664
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek May 9, 2023
347dff4
Bump dependency versions
waclawjacek May 9, 2023
4a3280a
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek May 16, 2023
34fad4a
Bump dependency versions
waclawjacek May 16, 2023
94923e2
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek May 30, 2023
fd7b349
Bump PHP version in E2E GH Action to 8.2
waclawjacek Jun 1, 2023
8e08043
Tweak changelog entry
waclawjacek Jun 1, 2023
ffd305d
Use `try_registration` instead of `register`
waclawjacek Jun 1, 2023
e5e2742
Replace JETPACK__VERSION and JETPACK__API_VERSION with newer variables
waclawjacek Jun 1, 2023
2e7930e
Merge branch 'frosso/jetpack-dependency-removal' of github.com:Automa…
waclawjacek Jun 1, 2023
8591173
Remove unnecessary backcompat check
waclawjacek Jun 1, 2023
53de389
Check for both user token and blog token
waclawjacek Jun 1, 2023
920d1b5
Remove argument from `get_access_token`
waclawjacek Jun 1, 2023
42fb786
Refactor connection owner-related methods
waclawjacek Jun 2, 2023
ffc4730
Explicitly require automattic/jetpack-status
waclawjacek Jun 2, 2023
cd61593
Deprecate WC_Connect_Jetpack::is_active() in favor of is_connected()
waclawjacek Jun 2, 2023
8ecbf99
Remove redundant class_exists check
waclawjacek Jun 2, 2023
116aa54
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek Jun 19, 2023
93b8d2f
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek Jul 25, 2023
c589b98
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek Jul 25, 2023
1c661f3
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek Aug 23, 2023
0f648a0
Replace status page "Jetpack" section with "WordPress.com Connection"…
waclawjacek Sep 4, 2023
6dedb1a
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek Sep 21, 2023
1a09584
Remove tests/php/mocks/jetpack.php and Jetpack installation from env …
waclawjacek Oct 11, 2023
3f51e55
Update copy: "Once you connect your site to WordPress.com"
waclawjacek Oct 17, 2023
e486487
Update TOS in NUX banner
waclawjacek Oct 17, 2023
45ca57e
Status page: Add WPCOM connection status "offline"
waclawjacek Oct 18, 2023
8fb6d83
Remove redundant $user_id argument
waclawjacek Oct 18, 2023
ee46bcf
Remove redundant has_connected_owner() check
waclawjacek Oct 18, 2023
1723baf
Refactor method name
waclawjacek Oct 18, 2023
b0e57d2
Replace is_current_user_connected() with is_current_user_connection_o…
waclawjacek Oct 18, 2023
637ced3
Replace enums with call to is_offline_mode()
waclawjacek Oct 18, 2023
9cba91c
Update PHPDoc
waclawjacek Oct 18, 2023
fa79986
Rename OFFLINE const to OFFLINE_MODE
waclawjacek Oct 18, 2023
c33c430
Remove obsolete can_accept_tos() method
waclawjacek Oct 18, 2023
f9e7b87
Settings: Remove offline mode notice width rule
waclawjacek Oct 18, 2023
569ad49
Refactor WC_Connect_Tracks
waclawjacek Oct 18, 2023
7cd2782
Only extract fields if object/array is set
waclawjacek Oct 18, 2023
573a363
release script: Run composer with --no-dev
waclawjacek Oct 18, 2023
42170ab
Update Composer deps
waclawjacek Oct 18, 2023
d9bb0f0
PHPDoc
waclawjacek Oct 18, 2023
9f319c4
Tests: Update NUX tests to the "no banners when offline" logic
waclawjacek Oct 18, 2023
21d3164
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek Oct 18, 2023
00fa75f
Remove obsolete checks (classes always present). Replace mentions of …
waclawjacek Oct 18, 2023
d1be417
composer.lock
waclawjacek Oct 18, 2023
e8ed1d2
Composer: Move Jetpack packages to "require" section
waclawjacek Oct 18, 2023
e5a96d3
Update changelog.txt
waclawjacek Oct 19, 2023
2104872
E2E: Give container more time to build
waclawjacek Oct 19, 2023
cf22022
Revert "E2E: Give container more time to build"
waclawjacek Oct 19, 2023
4140263
E2E: Add composer install
waclawjacek Oct 19, 2023
07b003e
Restore ability to accept TOS in offline mode
waclawjacek Oct 19, 2023
9433d62
Revert "Tests: Update NUX tests to the "no banners when offline" logic"
waclawjacek Oct 19, 2023
1d462d3
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek Oct 25, 2023
627283a
Update Sift tracker rendering to use new WC_Connect_Jetpack methods
waclawjacek Oct 25, 2023
702256c
Silence QIT warning about wp_redirect
waclawjacek Oct 24, 2023
5f6fc1a
Merge branch 'trunk' into frosso/jetpack-dependency-removal
waclawjacek Oct 26, 2023
1d90a66
Update wporg assets, details and installation steps
harriswong Oct 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions classes/class-wc-connect-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ protected function request_body( $initial_body = array() ) {
'dimension_unit' => strtolower( get_option( 'woocommerce_dimension_unit' ) ),
'weight_unit' => strtolower( get_option( 'woocommerce_weight_unit' ) ),
'wcs_version' => WC_Connect_Loader::get_wcs_version(),
'jetpack_version' => JETPACK__VERSION,
'jetpack_version' => defined( 'JETPACK__VERSION' ) ? JETPACK__VERSION : 'embed',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like we're doing anything on the server with this string. However, the server is still requiring it in the payload.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was only ever used for troubleshooting. If it's easy to get the version of the jetpack-connection package I would include it, otherwise embed is fine.

Copy link
Contributor

@waclawjacek waclawjacek Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just checked and we are not using it anywhere aside from Tracks calls. We require it to be a string if it is present.

I've changed this from embed to embed-{jetpack_connection_package_version}.

'is_atomic' => WC_Connect_Jetpack::is_atomic_site(),
'wc_version' => WC()->version,
'wp_version' => get_bloginfo( 'version' ),
Expand Down Expand Up @@ -529,7 +529,7 @@ protected function authorization_header() {
}

list( $token_key, $token_secret ) = explode( '.', $token->secret );
$token_key = sprintf( '%s:%d:%d', $token_key, JETPACK__API_VERSION, $token->external_user_id );
$token_key = sprintf( '%s:%d:%d', $token_key, defined( 'JETPACK__API_VERSION' ) ? JETPACK__API_VERSION : 'embed', $token->external_user_id );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server seems ok with this 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format is %s:%d:%d so the second and third placeholders should be numbers (i.e. can't be "embed"). Testing on my local, it looks like the code below returns 1 anyway so I suggest we hardcode it to that, and in the future use Jetpack's header building function instead of our own, if possible.

Constants::get_constant( 'JETPACK__API_VERSION' )

$time_diff = (int) Jetpack_Options::get_option( 'time_diff' );
$timestamp = time() + $time_diff;
$nonce = wp_generate_password( 10, false );
Expand Down
2 changes: 1 addition & 1 deletion classes/class-wc-connect-debug-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function woocommerce_debug_tools( $tools ) {
function test_connection() {
$test_request = $this->api_client->auth_test();
if ( $test_request && ! is_wp_error( $test_request ) && $test_request->authorized ) {
echo '<div class="updated inline"><p>' . __( 'Your site is succesfully communicating to the WooCommerce Shipping & Tax API.', 'woocommerce-services' ) . '</p></div>';
echo '<div class="updated inline"><p>' . __( 'Your site is successfully communicating to the WooCommerce Shipping & Tax API.', 'woocommerce-services' ) . '</p></div>';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else {
echo '<div class="error inline"><p>' . __( 'ERROR: Your site has a problem connecting to the WooCommerce Shipping & Tax API. Please make sure your Jetpack connection is working.', 'woocommerce-services' ) . '</p></div>';
}
Expand Down
26 changes: 7 additions & 19 deletions classes/class-wc-connect-help-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,7 @@ protected function get_health_items() {
// Check that Jetpack is connected
include_once ABSPATH . 'wp-admin/includes/plugin.php'; // required for is_plugin_active
$is_connected = WC_Connect_Jetpack::is_active() || WC_Connect_Jetpack::is_development_mode();
if ( ! is_plugin_active( 'jetpack/jetpack.php' ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for all this branching logic anymore - checking whether jetpack is installed or not won't matter, we are now using the composer packages directly.

$health_item = array(
'state' => 'error',
'message' => sprintf(
__( 'Please install and activate the Jetpack plugin, version %s or higher', 'woocommerce-services' ),
WOOCOMMERCE_CONNECT_MINIMUM_JETPACK_VERSION
),
);
} elseif ( version_compare( JETPACK__VERSION, WOOCOMMERCE_CONNECT_MINIMUM_JETPACK_VERSION, '<' ) ) {
$health_item = array(
'state' => 'error',
'message' => sprintf(
__( 'Jetpack %1$s or higher is required (You are running %2$s)', 'woocommerce-services' ),
WOOCOMMERCE_CONNECT_MINIMUM_JETPACK_VERSION,
JETPACK__VERSION
),
);
} elseif ( ! $is_connected ) {
if ( ! $is_connected ) {
$health_item = array(
'state' => 'error',
'message' => __( 'Jetpack is not connected to WordPress.com. Make sure the Jetpack plugin is installed, activated, and connected.', 'woocommerce-services' ),
Expand All @@ -102,14 +85,19 @@ protected function get_health_items() {
'state' => 'warning',
'message' => __( 'This is a Jetpack staging site', 'woocommerce-services' ),
);
} else {
} elseif ( defined( 'JETPACK__VERSION' ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really matter? IDK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to say no.

$health_item = array(
'state' => 'success',
'message' => sprintf(
__( 'Jetpack %s is connected and working correctly', 'woocommerce-services' ),
JETPACK__VERSION
),
);
} else {
$health_item = array(
'state' => 'success',
'message' => __( 'Jetpack is connected and working correctly', 'woocommerce-services' ),
);
}
$health_items['jetpack'] = $health_item;

Expand Down
103 changes: 34 additions & 69 deletions classes/class-wc-connect-jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,19 @@

if ( ! class_exists( 'WC_Connect_Jetpack' ) ) {
class WC_Connect_Jetpack {
const PLUGIN_SLUG = 'woocommerce-shipping-tax';

public static function get_connection_manager() {
return new Manager( self::PLUGIN_SLUG );
}

/**
* @param $user_id
*
* @return stdClass|WP_Error
*/
public static function get_master_user_access_token( $user_id ) {
if ( class_exists( '\Automattic\Jetpack\Connection\Tokens' ) && method_exists( '\Automattic\Jetpack\Connection\Tokens', 'get_access_token' ) ) {
$connection = new Tokens();

return $connection->get_access_token( $user_id );
}

if ( class_exists( '\Automattic\Jetpack\Connection\Manager' ) && method_exists( '\Automattic\Jetpack\Connection\Manager', 'get_access_token' ) ) {
$connection = new Manager();

return $connection->get_access_token( $user_id );
}

// fallback
return new stdClass();
return self::get_connection_manager()->get_tokens()->get_access_token( $user_id );
}

/**
Expand All @@ -35,6 +28,7 @@ public static function get_master_user_access_token( $user_id ) {
public static function is_development_mode() {
if ( method_exists( '\\Automattic\\Jetpack\\Status', 'is_offline_mode' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check seems to be excessive now as well, the Status package is either there or not.
And since we're loading the Connection package, it'll always be loaded as a dependency: https://github.com/Automattic/jetpack/blob/trunk/projects/packages/connection/composer.json#L11

However, it might make sense to load it directly in the plugin's composer.json for clarity and to prevent potential incompatibilities in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great ideas!

$status = new \Automattic\Jetpack\Status();

return $status->is_offline_mode();
}

Expand All @@ -47,14 +41,8 @@ public static function is_development_mode() {
* @return bool
*/
public static function is_active() {
if ( defined( 'WOOCOMMERCE_SERVICES_LOCAL_TEST_MODE' ) && WOOCOMMERCE_SERVICES_LOCAL_TEST_MODE ) {
return true;
}
if ( method_exists( 'Jetpack', 'is_active' ) ) {
return Jetpack::is_active();
}

return false;
// TODO: check
return self::get_connection_manager()->is_connected();
}

/**
Expand All @@ -63,16 +51,9 @@ public static function is_active() {
* @return bool
*/
public static function is_staging_site() {
if ( method_exists( '\\Automattic\\Jetpack\\Status', 'is_staging_site' ) ) {
$status = new \Automattic\Jetpack\Status();
return $status->is_staging_site();
}
$jetpack_status = new \Automattic\Jetpack\Status();

if ( method_exists( 'Jetpack', 'is_staging_site' ) ) {
return Jetpack::is_staging_site();
}

return false;
return $jetpack_status->is_staging_site();
}

/**
Expand All @@ -81,6 +62,7 @@ public static function is_staging_site() {
* @return bool
*/
public static function is_atomic_site() {
// TODO: WTH?
if ( function_exists( 'jetpack_is_atomic_site' ) ) {
return jetpack_is_atomic_site();
} elseif ( function_exists( 'jetpack_is_automated_transfer_site' ) ) {
Expand All @@ -91,17 +73,7 @@ public static function is_atomic_site() {
}

public static function get_connected_user_data( $user_id ) {
if ( class_exists( '\Automattic\Jetpack\Connection\Manager' ) && method_exists( '\Automattic\Jetpack\Connection\Manager', 'get_connected_user_data' ) ) {
$connection = new Manager();

return $connection->get_connected_user_data( $user_id );
}

if ( method_exists( 'Jetpack', 'get_connected_user_data' ) ) {
return Jetpack::get_connected_user_data( $user_id );
}

return false;
return self::get_connection_manager()->get_connected_user_data( $user_id );
}

/**
Expand All @@ -113,6 +85,7 @@ public static function get_master_user() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( self::is_active() && method_exists( 'Jetpack_Options', 'get_option' ) ) {
$master_user_id = Jetpack_Options::get_option( 'master_user' );

return get_userdata( $master_user_id );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend calling Manager::get_connection_owner() instead of pulling the data from options directly.


Expand All @@ -124,9 +97,11 @@ public static function get_master_user() {
* Builds a connect url
*
* @param $redirect_url
*
* @return string
*/
public static function build_connect_url( $redirect_url ) {
// TODO: gotta figure this out
return Jetpack::init()->build_connect_url(
true,
$redirect_url,
Expand All @@ -142,14 +117,12 @@ public static function build_connect_url( $redirect_url ) {
* @param
*/
public static function tracks_record_event( $user, $event_type, $data ) {
if ( version_compare( JETPACK__VERSION, '7.5', '<' ) ) {
if ( function_exists( 'jetpack_tracks_record_event' ) ) {
return jetpack_tracks_record_event( $user, $event_type, $data );
}
} elseif ( class_exists( 'Automattic\\Jetpack\\Tracking' ) ) {
if ( class_exists( 'Automattic\\Jetpack\\Tracking' ) ) {
waclawjacek marked this conversation as resolved.
Show resolved Hide resolved
$tracking = new Automattic\Jetpack\Tracking();

return $tracking->tracks_record_event( $user, $event_type, $data );
}

return false;
}

Expand All @@ -159,19 +132,7 @@ public static function tracks_record_event( $user, $event_type, $data ) {
* @return bool Whether or nor the current user is connected to Jetpack
*/
public static function is_current_user_connected() {
if ( class_exists( '\Automattic\Jetpack\Connection\Manager' ) && method_exists( '\Automattic\Jetpack\Connection\Manager', 'is_user_connected' ) ) {
$connection = new Manager();

return $connection->is_user_connected();
}

if ( defined( 'JETPACK_MASTER_USER' ) ) {
$user_token = self::get_master_user_access_token( JETPACK_MASTER_USER );

return ( isset( $user_token->external_user_id ) && get_current_user_id() === $user_token->external_user_id );
}

return false;
return self::get_connection_manager()->is_user_connected();
}

/**
Expand All @@ -180,19 +141,23 @@ public static function is_current_user_connected() {
* @return bool Whether or nor Jetpack is connected
*/
public static function is_connected() {
if ( class_exists( '\Automattic\Jetpack\Connection\Manager' ) && method_exists( '\Automattic\Jetpack\Connection\Manager', 'is_connected' ) ) {
$connection = new Manager();

return $connection->is_connected();
}
$manager = self::get_connection_manager();

if ( defined( 'JETPACK_MASTER_USER' ) ) {
$user_token = self::get_master_user_access_token( JETPACK_MASTER_USER );
return $manager->is_plugin_enabled() && $manager->has_connected_owner();
}

return isset( $user_token->external_user_id );
/**
* Check if WCS&T is installed alongside an old version of Jetpack (8.1 or earlier). Due to the autoloader code in those old
* versions, the Jetpack Config initialization code would just crash the site.
*
* @return bool True if the plugin can keep initializing itself, false otherwise.
*/
public static function is_jetpack_version_supported() {
if ( defined( 'JETPACK__VERSION' ) && version_compare( JETPACK__VERSION, '8.2', '<' ) && JETPACK__VERSION !== 'wpcom' ) {
return false;
}

return false;
return true;
}
}
}
46 changes: 4 additions & 42 deletions classes/class-wc-connect-nux.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ public static function get_banner_type_to_display( $status = array() ) {
This is an existing user. Do nothing.
*/
switch ( $status['jetpack_connection_status'] ) {
case self::JETPACK_NOT_INSTALLED:
case self::JETPACK_INSTALLED_NOT_ACTIVATED:
case self::JETPACK_ACTIVATED_NOT_CONNECTED:
return 'before_jetpack_connection';
case self::JETPACK_CONNECTED:
Expand Down Expand Up @@ -288,6 +286,9 @@ public static function get_banner_type_to_display( $status = array() ) {
}

public function get_jetpack_install_status() {
// TODO: check
return self::JETPACK_CONNECTED;

// we need to use validate_plugin to check that Jetpack is installed
include_once ABSPATH . 'wp-admin/includes/plugin.php';

Expand Down Expand Up @@ -417,10 +418,6 @@ public function set_up_nux_notices() {
// Admins might not be able to install or activate plugins, but Jetpack might already have been installed by a superadmin.
// If this is the case, the admin can connect the site on their own, and should be able to use WCS as ususal
$jetpack_install_status = $this->get_jetpack_install_status();
if ( ( self::JETPACK_NOT_INSTALLED === $jetpack_install_status && ! current_user_can( 'install_plugins' ) )
|| ( self::JETPACK_INSTALLED_NOT_ACTIVATED === $jetpack_install_status && ! current_user_can( 'activate_plugins' ) ) ) {
return;
}

$banner_to_display = self::get_banner_type_to_display(
array(
Expand All @@ -446,10 +443,6 @@ public function set_up_nux_notices() {
);
wp_enqueue_script( 'wc_connect_banner' );
wp_localize_script( 'wc_connect_banner', 'wcs_nux_notice', $ajax_data );
add_action(
'wp_ajax_woocommerce_services_activate_jetpack',
array( $this, 'ajax_activate_jetpack' )
);
add_action(
'wp_ajax_woocommerce_services_get_jetpack_connect_url',
array( $this, 'ajax_get_jetpack_connect_url' )
Expand Down Expand Up @@ -508,14 +501,13 @@ public function show_banner_before_connection() {

$country = WC()->countries->get_base_country();
/* translators: %s: list of features, potentially comma separated */
$description_base = __( "WooCommerce Shipping & Tax is almost ready to go! Once you connect Jetpack you'll have access to %s.", 'woocommerce-services' );
$description_base = __( "WooCommerce Shipping & Tax is almost ready to go! Once you connect your site you'll have access to %s.", 'woocommerce-services' );
$feature_list = $this->get_feature_list_for_country( $country );
$banner_content = array(
'title' => $banner_title,
'description' => sprintf( $description_base, $feature_list ),
'button_text' => $button_text,
'image_url' => $image_url,
'should_show_jp' => true,
'should_show_terms' => true,
);

Expand Down Expand Up @@ -563,7 +555,6 @@ public function show_banner_after_connection() {
'images/wcs-notice.png',
dirname( __FILE__ )
),
'should_show_jp' => false,
'should_show_terms' => false,
)
);
Expand Down Expand Up @@ -606,7 +597,6 @@ public function show_tos_banner() {
'images/wcs-notice.png',
dirname( __FILE__ )
),
'should_show_jp' => false,
'should_show_terms' => true,
)
);
Expand All @@ -620,12 +610,6 @@ public function show_nux_banner( $content ) {
?>
<div class="notice wcs-nux__notice <?php echo isset( $content['dismissible_id'] ) ? 'is-dismissible' : ''; ?>">
<div class="wcs-nux__notice-logo <?php echo isset( $content['compact_logo'] ) && $content['compact_logo'] ? 'is-compact' : ''; ?>">
<?php if ( $content['should_show_jp'] ) : ?>
<img
class="wcs-nux__notice-logo-jetpack"
src="<?php echo esc_url( plugins_url( 'images/jetpack-logo.png', dirname( __FILE__ ) ) ); ?>"
>
<?php endif; ?>
<img class="wcs-nux__notice-logo-graphic" src="<?php echo esc_url( $content['image_url'] ); ?>">
</div>
<div class="wcs-nux__notice-content">
Expand Down Expand Up @@ -691,28 +675,6 @@ class="woocommerce-services__connect-jetpack wcs-nux__notice-content-button butt
endif;
}

/**
* Activates Jetpack after an ajax request
*/
public function ajax_activate_jetpack() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to activate jetpack anymore

check_ajax_referer( 'wcs_nux_notice' );

$result = activate_plugin( 'jetpack/jetpack.php' );

if ( is_null( $result ) ) {
// The function activate_plugin() returns NULL on success.
echo 'success';
} else {
if ( is_wp_error( $result ) ) {
echo esc_html( $result->get_error_message() );
} else {
echo 'error';
}
}

wp_die();
}

/**
* Get Jetpack connection URL.
*/
Expand Down
2 changes: 1 addition & 1 deletion classes/class-wc-connect-tracks.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function record_user_event( $event_type, $data = array() ) {
}

// Check for Jetpack
$jp_version = 'unavailable';
$jp_version = 'embed';
if ( defined( 'JETPACK__VERSION' ) ) {
$jp_version = JETPACK__VERSION;
}
Expand Down
Loading