From e6d06b5d5401c3faf9060b00f6485e6b6d837f9f Mon Sep 17 00:00:00 2001 From: Ilyas Foo Date: Tue, 3 Sep 2024 14:58:09 +0800 Subject: [PATCH 1/4] Add conditional check to replace launch-site task with LYS task --- includes/class-wc-calypso-bridge-setup-tasks.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/includes/class-wc-calypso-bridge-setup-tasks.php b/includes/class-wc-calypso-bridge-setup-tasks.php index 37d395f7..05b86d6e 100644 --- a/includes/class-wc-calypso-bridge-setup-tasks.php +++ b/includes/class-wc-calypso-bridge-setup-tasks.php @@ -110,15 +110,18 @@ public function add_tasks() { $tl = \Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists::instance(); require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-add-domain.php'; - require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-launch-site.php'; $list = $tl::get_lists_by_ids( array( 'setup' ) ); $list = array_pop( $list ); $add_domain_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\AddDomain( $list ); - $launch_site_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\LaunchSite( $list ); $tl::add_task( 'setup', $add_domain_task ); - $tl::add_task( 'setup', $launch_site_task ); + + if ( ! class_exists( '\Automattic\WooCommerce\Admin\Features\Features' ) || ! \Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'launch-your-store' ) ) { + require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-launch-site.php'; + $launch_site_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\LaunchSite( $list ); + $tl::add_task( 'setup', $launch_site_task ); + } } /** From a7507f175c916a2628002e562a8cd9ed179dbbcd Mon Sep 17 00:00:00 2001 From: Ilyas Foo Date: Tue, 3 Sep 2024 16:02:12 +0800 Subject: [PATCH 2/4] Changelog --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index e99f7ce2..71591e53 100644 --- a/readme.txt +++ b/readme.txt @@ -28,6 +28,7 @@ This section describes how to install the plugin and get it working. * Sync WPCOM coming soon status to LYS #1502 * Add sync coming soon status from LYS to WPCOM #1503 * Refactor LYS to use unidirectional data flow #1506 +* Add conditional check to replace launch-site task with LYS task #1509 = 2.5.5 = * Add a new class to customize for Stripe from Partner Aware Onboarding #1492 From c695309f06196a17701aa566ccaf47bb6cc83227 Mon Sep 17 00:00:00 2001 From: Ilyas Foo Date: Tue, 3 Sep 2024 16:48:43 +0800 Subject: [PATCH 3/4] Merge add_tasks function with replace_tasks to consolidate logic and apply proper sorting --- .../class-wc-calypso-bridge-setup-tasks.php | 50 +++++++------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/includes/class-wc-calypso-bridge-setup-tasks.php b/includes/class-wc-calypso-bridge-setup-tasks.php index 05b86d6e..ec6628f6 100644 --- a/includes/class-wc-calypso-bridge-setup-tasks.php +++ b/includes/class-wc-calypso-bridge-setup-tasks.php @@ -42,7 +42,6 @@ private function __construct() { // All plans. add_action( 'load-woocommerce_page_wc-settings', array( $this, 'redirect_store_details_onboarding' ) ); add_action( 'wp_ajax_launch_store', array( $this, 'handle_ajax_launch_endpoint' ) ); - add_action( 'init', array( $this, 'add_tasks' ) ); add_filter( 'woocommerce_admin_experimental_onboarding_tasklists', [ $this, 'replace_tasks' ] ); add_filter( 'get_user_metadata', array( $this, 'override_user_meta_field' ), 10, 4 ); } @@ -86,14 +85,9 @@ public function handle_ajax_launch_endpoint() { } /** - * Add Setup Tasks. + * Add and replace setup tasks. */ - public function add_tasks() { - - if ( ! class_exists( '\Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists' ) ) { - return; - } - + public function replace_tasks( $lists ) { /** * `ecommerce_custom_setup_tasks_enabled` filter. * @@ -104,30 +98,7 @@ public function add_tasks() { * @param bool $status_enabled * @return bool */ - if ( ! (bool) apply_filters( 'ecommerce_custom_setup_tasks_enabled', true ) ) { - return; - } - - $tl = \Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists::instance(); - require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-add-domain.php'; - - $list = $tl::get_lists_by_ids( array( 'setup' ) ); - $list = array_pop( $list ); - - $add_domain_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\AddDomain( $list ); - $tl::add_task( 'setup', $add_domain_task ); - - if ( ! class_exists( '\Automattic\WooCommerce\Admin\Features\Features' ) || ! \Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'launch-your-store' ) ) { - require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-launch-site.php'; - $launch_site_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\LaunchSite( $list ); - $tl::add_task( 'setup', $launch_site_task ); - } - } - - /** - * Replace setup tasks. - */ - public function replace_tasks( $lists ) { + $ecommerce_custom_setup_tasks_enabled = (bool) apply_filters( 'ecommerce_custom_setup_tasks_enabled', true ); if ( isset( $lists['setup'] ) ) { // Default product task index. $product_task_index = 2; @@ -144,6 +115,15 @@ public function replace_tasks( $lists ) { // Remove appearance and purchase task. unset( $lists['setup']->tasks[$index] ); break; + case 'launch-your-store': + case 'launch_site': + if ( $ecommerce_custom_setup_tasks_enabled ) { + // Append add domain task after launch your store task. + require_once __DIR__ . '/tasks/class-wc-calypso-task-add-domain.php'; + $add_domain_task = array( new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\AddDomain( $lists['setup'] ) ); + array_splice( $lists['setup']->tasks, $index, 0, $add_domain_task ); + } + break; } } @@ -153,6 +133,12 @@ public function replace_tasks( $lists ) { $appearance_task = array( new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\WCBridgeAppearance( $lists['setup'] ) ); array_splice( $lists['setup']->tasks, $product_task_index, 0, $appearance_task ); } + + if ( ! Features::is_enabled( 'launch-your-store' ) && $ecommerce_custom_setup_tasks_enabled ) { + require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-launch-site.php'; + $launch_site_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\LaunchSite( $lists['setup'] ); + $lists['setup']->tasks[] = $launch_site_task; + } } return $lists; } From 6e67ae3880f212c8be343afc85d24f6bb7c377f7 Mon Sep 17 00:00:00 2001 From: Ilyas Foo Date: Tue, 3 Sep 2024 17:02:54 +0800 Subject: [PATCH 4/4] Move logic around to simplify it more --- includes/class-wc-calypso-bridge-setup-tasks.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/class-wc-calypso-bridge-setup-tasks.php b/includes/class-wc-calypso-bridge-setup-tasks.php index ec6628f6..1edc0f2b 100644 --- a/includes/class-wc-calypso-bridge-setup-tasks.php +++ b/includes/class-wc-calypso-bridge-setup-tasks.php @@ -116,12 +116,18 @@ public function replace_tasks( $lists ) { unset( $lists['setup']->tasks[$index] ); break; case 'launch-your-store': - case 'launch_site': if ( $ecommerce_custom_setup_tasks_enabled ) { - // Append add domain task after launch your store task. + // Append add domain task before launch your store task. require_once __DIR__ . '/tasks/class-wc-calypso-task-add-domain.php'; $add_domain_task = array( new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\AddDomain( $lists['setup'] ) ); array_splice( $lists['setup']->tasks, $index, 0, $add_domain_task ); + + // Replace launch your store task with launch site task. + if ( ! Features::is_enabled( 'launch-your-store' ) ) { + require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-launch-site.php'; + $launch_site_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\LaunchSite( $lists['setup'] ); + $lists['setup']->tasks[$index + 1] = $launch_site_task; + } } break; } @@ -133,12 +139,6 @@ public function replace_tasks( $lists ) { $appearance_task = array( new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\WCBridgeAppearance( $lists['setup'] ) ); array_splice( $lists['setup']->tasks, $product_task_index, 0, $appearance_task ); } - - if ( ! Features::is_enabled( 'launch-your-store' ) && $ecommerce_custom_setup_tasks_enabled ) { - require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-launch-site.php'; - $launch_site_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\LaunchSite( $lists['setup'] ); - $lists['setup']->tasks[] = $launch_site_task; - } } return $lists; }