From 243901a38fc28d7788b5c2218cb050a259eca882 Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Wed, 29 Jan 2020 22:47:04 +0800 Subject: [PATCH] Onboarding: Mark profiler complete on WC update (https://github.com/woocommerce/woocommerce-admin/pull/3590) * Mark profiler as complete if previous onboarding install has been handled * Load features before WC updated hooks * Add todo note about updating core install check --- .../src/Features/Onboarding.php | 24 +++++++++++++++++++ plugins/woocommerce-admin/src/Loader.php | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-admin/src/Features/Onboarding.php b/plugins/woocommerce-admin/src/Features/Onboarding.php index 660a5ee83dd..4fcfe735bab 100644 --- a/plugins/woocommerce-admin/src/Features/Onboarding.php +++ b/plugins/woocommerce-admin/src/Features/Onboarding.php @@ -63,6 +63,7 @@ class Onboarding { // Adds the ability to toggle the new onboarding experience on or off. // @todo This option should be removed when merging the onboarding feature to core. add_action( 'current_screen', array( $this, 'enable_onboarding' ) ); + add_action( 'woocommerce_updated', array( $this, 'maybe_mark_complete' ) ); if ( ! Loader::is_onboarding_enabled() ) { add_action( 'current_screen', array( $this, 'update_help_tab' ), 60 ); @@ -938,4 +939,27 @@ class Onboarding { wp_safe_redirect( wc_admin_url() ); } + + /** + * When updating WooCommerce, mark the profiler and task list complete. + * + * @todo The `maybe_enable_setup_wizard()` method should be revamped on onboarding enable in core. + * See https://github.com/woocommerce/woocommerce/blob/1ca791f8f2325fe2ee0947b9c47e6a4627366374/includes/class-wc-install.php#L341 + */ + public static function maybe_mark_complete() { + // The install notice still exists so don't complete the profiler. + if ( ! class_exists( 'WC_Admin_Notices' ) || \WC_Admin_Notices::has_notice( 'install' ) ) { + return; + } + + $onboarding_data = get_option( self::PROFILE_DATA_OPTION, array() ); + // Don't make updates if the profiler is completed, but task list is potentially incomplete. + if ( isset( $onboarding_data['completed'] ) && $onboarding_data['completed'] ) { + return; + } + + $onboarding_data['completed'] = true; + update_option( self::PROFILE_DATA_OPTION, $onboarding_data ); + update_option( 'woocommerce_task_list_hidden', 'yes' ); + } } diff --git a/plugins/woocommerce-admin/src/Loader.php b/plugins/woocommerce-admin/src/Loader.php index e1f831b9427..b0274040616 100644 --- a/plugins/woocommerce-admin/src/Loader.php +++ b/plugins/woocommerce-admin/src/Loader.php @@ -57,7 +57,8 @@ class Loader { */ public function __construct() { add_action( 'init', array( __CLASS__, 'define_tables' ) ); - add_action( 'init', array( __CLASS__, 'load_features' ) ); + // Load feature before WooCommerce update hooks. + add_action( 'init', array( __CLASS__, 'load_features' ), 4 ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'register_scripts' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'inject_wc_settings_dependencies' ), 14 ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_scripts' ), 15 );