Skip to content

Commit f0d1939

Browse files
committed
Introduce abandoned status
this should help us with edge cases to permit onboarding re-entry so it's not a black and white case as previous
1 parent ade77bb commit f0d1939

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

includes/Services/AppService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public function complete( string $selected_sitegen_homepage ): void {
5656
// Trash Preview pages.
5757
PreviewsService::trash_preview_pages();
5858

59+
// Mark onboarding as completed.
60+
StatusService::handle_completed();
61+
5962
// Purge all caches.
6063
container()->get( 'cachePurger' )->purge_all();
6164

includes/Services/StatusService.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ public static function handle_started(): bool {
2828
return false;
2929
}
3030

31+
/**
32+
* Handles Onboarding abandoned event.
33+
*
34+
* @return void
35+
*/
36+
public static function handle_abandoned(): void {
37+
if ( 'started' === get_option( Options::get_option_name( 'status' ) ) ) {
38+
update_option( Options::get_option_name( 'status' ), 'abandoned' );
39+
}
40+
}
41+
3142
/**
3243
* Handles Onboarding completed event.
3344
*
@@ -164,22 +175,17 @@ public static function update_onboarding_restart_status(): void {
164175
* @return void
165176
*/
166177
public static function track(): void {
167-
global $pagenow;
168-
178+
// Ignore if the request is an AJAX request.
169179
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
170180
return;
171181
}
172182

173-
switch ( $pagenow ) {
174-
case 'index.php':
175-
// If the page is not nfd-onboarding.
176-
//phpcs:ignore
177-
if ( isset( $_GET['page'] ) && WP_Admin::$slug !== \sanitize_text_field( $_GET['page'] ) ) {
178-
self::handle_completed();
179-
}
180-
break;
181-
default:
182-
self::handle_completed();
183+
// Ignore if the request is not for the onboarding page.
184+
if ( isset( $_GET['page'] ) && WP_Admin::$slug === \sanitize_text_field( $_GET['page'] ) ) {
185+
return;
183186
}
187+
188+
// Handle abandoned event.
189+
self::handle_abandoned();
184190
}
185191
}

0 commit comments

Comments
 (0)