From 68f0496c63aa6f90c37e88733ef2d77e7a3e2d3b Mon Sep 17 00:00:00 2001 From: Marcin Bot Date: Fri, 4 Sep 2020 14:46:52 +0100 Subject: [PATCH] Onboarding: Do not redirect if installed in the WC setup wizard (#869) * Onboarding: Do not redirect if installed in the WC setup wizard * Only redirect after activating the plugin on its own * Add the changelog entry --- changelog.txt | 3 +++ includes/class-wc-payments-account.php | 36 ++------------------------ readme.txt | 3 +++ woocommerce-payments.php | 21 +++++++++++++++ 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/changelog.txt b/changelog.txt index 1e02cdd1eb1..5eadf0dc1f0 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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. diff --git a/includes/class-wc-payments-account.php b/includes/class-wc-payments-account.php index ff3c1710b0b..0ddfb69fe4d 100644 --- a/includes/class-wc-payments-account.php +++ b/includes/class-wc-payments-account.php @@ -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 ); } /** @@ -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; diff --git a/readme.txt b/readme.txt index 58eb06d6f41..3e919602361 100644 --- a/readme.txt +++ b/readme.txt @@ -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. diff --git a/woocommerce-payments.php b/woocommerce-payments.php index a60506be4db..7709ea5891f 100644 --- a/woocommerce-payments.php +++ b/woocommerce-payments.php @@ -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. */