Skip to content

Commit

Permalink
Onboarding: Do not redirect if installed in the WC setup wizard (#869)
Browse files Browse the repository at this point in the history
* Onboarding: Do not redirect if installed in the WC setup wizard

* Only redirect after activating the plugin on its own

* Add the changelog entry
  • Loading branch information
marcinbot authored Sep 4, 2020
1 parent 0fc2c45 commit 68f0496
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*** WooCommerce Payments Changelog ***

= 1.4.1 - 2020-xx-xx =
* Fix - Only redirect to the onboarding screen if the plugin has been individually activated using the plugins page.

= 1.4.0 - 2020-09-02 =
* Add - Initial support for WooCommerce Subscriptions: Signing up for subscriptions, scheduled payments, and customer-initiated payment method changes.
* Add - Added a link to transaction details from order screens.
Expand Down
36 changes: 2 additions & 34 deletions includes/class-wc-payments-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,39 +210,7 @@ private function should_redirect_to_onboarding() {
return true;
}

// If already redirected to onboarding in the past, don't do it again.
if ( get_option( 'wcpay_redirected_to_onboarding', false ) ) {
return false;
}

// If onboarding new accounts is disabled, so it's pointless to redirect users to the splash page.
if ( self::is_on_boarding_disabled() ) {
return false;
}

// Don't hijack WP-Admin if the user is bulk-activating plugins.
if ( isset( $_GET['activate-multi'] ) ) {
return false;
}

// Don't redirect if the user is in the WC setup wizard.
$current_page = isset( $_GET['page'] ) ? wp_unslash( $_GET['page'] ) : null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( 'wc-setup' === $current_page ) {
return false;
}

// Don't redirect if the user is on the WC-Admin setup profiler or WC-Admin dashboard with the task list.
if ( 'wc-admin' === $current_page && empty( $_GET['path'] )
&& ( Onboarding::should_show_profiler() || Onboarding::should_show_tasks() ) ) {
return false;
}

// Don't redirect if the user is on Jetpack pages.
if ( 'jetpack' === $current_page ) {
return false;
}

return true;
return get_option( 'wcpay_should_redirect_to_onboarding', false );
}

/**
Expand All @@ -264,7 +232,7 @@ public function check_stripe_account_status() {

if ( empty( $account ) ) {
if ( $this->should_redirect_to_onboarding() ) {
update_option( 'wcpay_redirected_to_onboarding', true );
update_option( 'wcpay_should_redirect_to_onboarding', false );
$this->redirect_to_onboarding_page();
}
return false;
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ You can read our Terms of Service [here](https://en.wordpress.com/tos).

== Changelog ==

= 1.4.1 - 2020-xx-xx =
* Fix - Only redirect to the onboarding screen if the plugin has been individually activated using the plugins page.

= 1.4.0 - 2020-09-02 =
* Add - Initial support for WooCommerce Subscriptions: Signing up for subscriptions, scheduled payments, and customer-initiated payment method changes.
* Add - Added a link to transaction details from order screens.
Expand Down
21 changes: 21 additions & 0 deletions woocommerce-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@

require_once WCPAY_ABSPATH . 'vendor/autoload_packages.php';

/**
* Plugin activation hook.
*/
function wcpay_activate() {
// Do not take any action if activated in a REST request (via wc-admin).
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
return;
}

if (
// Only redirect to onboarding when activated on its own. Either with a link...
isset( $_GET['action'] ) && 'activate' === $_GET['action'] // phpcs:ignore WordPress.Security.NonceVerification
// ...or with a bulk action.
|| isset( $_POST['checked'] ) && is_array( $_POST['checked'] ) && 1 === count( $_POST['checked'] ) // phpcs:ignore WordPress.Security.NonceVerification
) {
update_option( 'wcpay_should_redirect_to_onboarding', true );
}
}

register_activation_hook( __FILE__, 'wcpay_activate' );

/**
* Initialize the Jetpack connection functionality.
*/
Expand Down

0 comments on commit 68f0496

Please sign in to comment.