Skip to content

Commit a421df0

Browse files
authored
Merge pull request #819 from newfold-labs/add/onboarding-site-info-option
saving site info in options table
2 parents 0c8cd20 + 2bf2fb2 commit a421df0

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

includes/Services/AppService.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
use NewfoldLabs\WP\Module\Onboarding\Data\Services\PreviewsService;
88
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService as LegacySiteGenService;
99

10-
1110
use function NewfoldLabs\WP\ModuleLoader\container;
1211

12+
/**
13+
* App Service for handling onboarding application lifecycle.
14+
*
15+
* This service manages the start and completion of the onboarding process,
16+
* including initialization of required services, publishing selected content,
17+
* and saving site information for other modules to access.
18+
*/
1319
class AppService {
1420

1521
/**
@@ -45,13 +51,13 @@ public function start(): void {
4551
*
4652
* @param string $selected_sitegen_homepage The selected sitegen homepage to publish.
4753
* @return void
48-
* @throws \Exception
54+
* @throws \Exception When homepage publishing fails.
4955
*/
5056
public function complete( string $selected_sitegen_homepage ): void {
5157
// Publish selected homepage.
5258
$result = ( new SiteGenService() )->publish_homepage( $selected_sitegen_homepage );
5359
if ( \is_wp_error( $result ) ) {
54-
throw new \Exception( $result->get_error_message() );
60+
throw new \Exception( esc_html( $result->get_error_message() ) );
5561
}
5662
// Trash Preview pages.
5763
PreviewsService::trash_preview_pages();
@@ -69,8 +75,8 @@ public function complete( string $selected_sitegen_homepage ): void {
6975
array(
7076
'label_key' => 'value',
7177
),
72-
__( 'Help us improve', 'wp-module-onboarding-data' ),
73-
__( 'How satisfied were you with the ease of creating your website?', 'wp-module-onboarding-data' ),
78+
__( 'Help us improve', 'wp-module-onboarding' ),
79+
__( 'How satisfied were you with the ease of creating your website?', 'wp-module-onboarding' ),
7480
);
7581
}
7682
}

includes/Services/StatusService.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use NewfoldLabs\WP\Module\Onboarding\Data\Config;
88
use NewfoldLabs\WP\Module\Onboarding\Data\Flows\Flows;
99
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService;
10+
use NewfoldLabs\WP\Module\Onboarding\Services\ReduxStateService;
1011

1112
/**
1213
* Tracks the Status of Onboarding.
@@ -47,6 +48,10 @@ public static function handle_abandoned(): void {
4748
public static function handle_completed(): void {
4849
if ( 'started' === get_option( Options::get_option_name( 'status' ) ) ) {
4950
update_option( Options::get_option_name( 'status' ), 'completed' );
51+
52+
// Save onboarding site information to database option.
53+
self::save_site_info();
54+
5055
/**
5156
* We're disabling the restart onboarding feature for now.
5257
*/
@@ -181,11 +186,28 @@ public static function track(): void {
181186
}
182187

183188
// Ignore if the request is not for the onboarding page.
184-
if ( isset( $_GET['page'] ) && WP_Admin::$slug === \sanitize_text_field( $_GET['page'] ) ) {
189+
if ( isset( $_GET['page'] ) && \sanitize_text_field( $_GET['page'] ) === WP_Admin::$slug ) {
185190
return;
186191
}
187192

188193
// Handle abandoned event.
189194
self::handle_abandoned();
190195
}
196+
197+
/**
198+
* Save onboarding site information to database option for other modules to access.
199+
*
200+
* @return void
201+
*/
202+
public static function save_site_info(): void {
203+
$site_info = array();
204+
205+
// Get experience level and site type from ReduxStateService
206+
$data = ReduxStateService::get( 'input' );
207+
$site_info['experience_level'] = $data['experienceLevel'] ?? 'advanced';
208+
$site_info['site_type'] = $data['siteType'] ?? 'business';
209+
210+
// Save to database option
211+
update_option( Options::get_option_name( 'site_info' ), $site_info );
212+
}
191213
}

0 commit comments

Comments
 (0)