From a2bff95a4a7f99384ed0cd94db3dfb7638e0b3a6 Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Thu, 2 Jan 2020 10:30:12 +0800 Subject: [PATCH] Onboarding: Redirect the user to the task list if referer is wccom checkout (https://github.com/woocommerce/woocommerce-admin/pull/3495) --- .../src/Features/Onboarding.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/woocommerce-admin/src/Features/Onboarding.php b/plugins/woocommerce-admin/src/Features/Onboarding.php index fd2584d82f2..cc1c5b264c8 100644 --- a/plugins/woocommerce-admin/src/Features/Onboarding.php +++ b/plugins/woocommerce-admin/src/Features/Onboarding.php @@ -86,6 +86,7 @@ class Onboarding { add_action( 'current_screen', array( $this, 'reset_profiler' ) ); add_action( 'current_screen', array( $this, 'reset_task_list' ) ); add_action( 'current_screen', array( $this, 'calypso_tests' ) ); + add_action( 'current_screen', array( $this, 'redirect_wccom_install' ) ); add_filter( 'woocommerce_admin_is_loading', array( $this, 'is_loading' ) ); add_filter( 'woocommerce_show_admin_notice', array( $this, 'remove_install_notice' ), 10, 2 ); } @@ -898,4 +899,21 @@ class Onboarding { return $show; } + + /** + * Redirects the user to the task list if the task list is enabled and finishing a wccom checkout. + * + * @todo Once URL params are added to the redirect, we can check those instead of the referer. + */ + public static function redirect_wccom_install() { + if ( + ! self::should_show_tasks() || + ! isset( $_SERVER['HTTP_REFERER'] ) || + 0 !== strpos( $_SERVER['HTTP_REFERER'], 'https://woocommerce.com/checkout' ) // phpcs:ignore sanitization ok. + ) { + return; + } + + wp_safe_redirect( wc_admin_url() ); + } }