Skip to content

Commit 583be3c

Browse files
authored
Merge pull request #736 from ProgressPlanner/filip/playground-onboarding
Delay onboarding init a bit
2 parents 2c5d373 + 5c0f607 commit 583be3c

File tree

4 files changed

+45
-48
lines changed

4 files changed

+45
-48
lines changed

assets/js/onboarding/onboarding.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,17 @@ class ProgressPlannerOnboardWizard {
373373
this.state.data.finished =
374374
this.state.currentStep === this.tourSteps.length - 1;
375375
this.closeTour();
376+
377+
// If on PP Dashboard page and privacy was accepted during onboarding,
378+
// refresh the page to properly initialize dashboard components.
379+
if (
380+
this.state.data.privacyAccepted &&
381+
window.location.href.includes(
382+
'admin.php?page=progress-planner'
383+
)
384+
) {
385+
window.location.reload();
386+
}
376387
} );
377388
}
378389
} else {

classes/class-onboard-wizard.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,36 @@
1212
*/
1313
class Onboard_Wizard {
1414

15+
/**
16+
* Option name for storing onboarding progress.
17+
*
18+
* @var string
19+
*/
20+
public const PROGRESS_OPTION_NAME = 'prpl_onboard_progress';
21+
1522
/**
1623
* Steps and their order.
1724
*
1825
* @var array
1926
*/
2027
protected $steps = [];
2128

29+
/**
30+
* Delete the onboarding progress option.
31+
*
32+
* @return bool True if the option was deleted, false otherwise.
33+
*/
34+
public static function delete_progress() {
35+
return \delete_option( self::PROGRESS_OPTION_NAME );
36+
}
37+
2238
/**
2339
* Constructor.
2440
*
2541
* @return void
2642
*/
2743
public function __construct() {
28-
\add_action( 'init', [ $this, 'maybe_register_popover_hooks' ], 0 );
44+
\add_action( 'init', [ $this, 'maybe_register_popover_hooks' ], 10 ); // Wait for the Playground to register its hooks.
2945
}
3046

3147
/**
@@ -52,7 +68,7 @@ public function maybe_register_popover_hooks() {
5268
// 3. Branded site (privacy auto-accepted, but still needs onboarding).
5369
$is_branded = 0 !== (int) \progress_planner()->get_ui__branding()->get_branding_id();
5470
$show_onboarding = ! \progress_planner()->is_privacy_policy_accepted()
55-
|| \get_option( 'prpl_onboard_progress', false )
71+
|| \get_option( self::PROGRESS_OPTION_NAME, false )
5672
|| $is_branded;
5773

5874
/**
@@ -319,7 +335,7 @@ protected function get_saved_progress() {
319335
return null;
320336
}
321337

322-
$onboarding_progress = \get_option( 'prpl_onboard_progress', true );
338+
$onboarding_progress = \get_option( self::PROGRESS_OPTION_NAME, true );
323339
if ( ! $onboarding_progress ) {
324340
return null;
325341
}
@@ -363,7 +379,7 @@ public function ajax_save_onboarding_progress() {
363379
\error_log( print_r( $progress, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r, WordPress.PHP.DevelopmentFunctions.error_log_error_log
364380

365381
// Save as user meta?
366-
\update_option( 'prpl_onboard_progress', $progress );
382+
\update_option( self::PROGRESS_OPTION_NAME, $progress );
367383

368384
\wp_send_json_success( [ 'message' => \esc_html__( 'Tour progress saved.', 'progress-planner' ) ] );
369385
}

classes/utils/class-debug-tools.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ public function check_delete_onboarding_progress() {
791791
$this->verify_nonce();
792792

793793
// Delete the onboarding progress.
794-
\delete_option( 'prpl_onboard_progress' );
794+
\Progress_Planner\Onboard_Wizard::delete_progress();
795795

796796
// Delete the license key.
797797
\delete_option( 'progress_planner_license_key' );

classes/utils/class-playground.php

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public function register_hooks() {
3131
if ( ! \progress_planner()->get_license_key() && ! \get_option( 'progress_planner_demo_data_generated', false ) ) {
3232
$this->generate_data();
3333
\update_option( 'progress_planner_license_key', \str_replace( ' ', '-', $this->create_random_string( 20 ) ) );
34-
\update_option( 'progress_planner_force_show_onboarding', false );
3534
\update_option(
3635
'progress_planner_todo',
3736
[
@@ -48,7 +47,6 @@ public function register_hooks() {
4847
\update_option( 'progress_planner_demo_data_generated', true );
4948
}
5049
\add_action( 'progress_planner_admin_page_header_before', [ $this, 'show_header_notice' ] );
51-
\add_action( 'wp_ajax_progress_planner_hide_onboarding', [ $this, 'hide_onboarding' ] );
5250
\add_action( 'wp_ajax_progress_planner_show_onboarding', [ $this, 'show_onboarding' ] );
5351

5452
\progress_planner()->get_settings()->set( 'activation_date', ( new \DateTime() )->modify( '-2 months' )->format( 'Y-m-d' ) );
@@ -80,48 +78,23 @@ public function enable_debug_tools() {
8078
}
8179

8280
/**
83-
* Toggle the onboarding visibility in the Playground environment.
84-
*
85-
* @param string $action Either 'show' or 'hide'.
81+
* Show the onboarding in the Playground environment.
8682
*
8783
* @return void
8884
*/
89-
private function toggle_onboarding( $action ) {
90-
$nonce_action = "progress_planner_{$action}_onboarding";
91-
\check_ajax_referer( $nonce_action, 'nonce' );
85+
public function show_onboarding() {
86+
\check_ajax_referer( 'progress_planner_show_onboarding', 'nonce' );
9287

9388
if ( ! \current_user_can( 'manage_options' ) ) {
9489
\wp_die( \esc_html__( 'You do not have sufficient permissions to access this page.', 'progress-planner' ) );
9590
}
9691

97-
if ( $action === 'hide' ) {
98-
\add_option( 'progress_planner_license_key', \str_replace( ' ', '-', $this->create_random_string( 20 ) ) );
99-
$message = \esc_html__( 'Onboarding hidden successfully', 'progress-planner' );
100-
} else {
101-
\delete_option( 'progress_planner_license_key' );
102-
$message = \esc_html__( 'Onboarding shown successfully', 'progress-planner' );
103-
}
104-
\update_option( 'progress_planner_force_show_onboarding', $action !== 'hide' );
105-
106-
\wp_send_json_success( [ 'message' => $message ] );
107-
}
108-
109-
/**
110-
* Hide the onboarding in the Playground environment.
111-
*
112-
* @return void
113-
*/
114-
public function hide_onboarding() {
115-
$this->toggle_onboarding( 'hide' );
116-
}
92+
// Delete onboarding progress to trigger fresh onboarding.
93+
\Progress_Planner\Onboard_Wizard::delete_progress();
94+
// Delete the license key to trigger onboarding (privacy not accepted).
95+
\delete_option( 'progress_planner_license_key' );
11796

118-
/**
119-
* Show the onboarding in the Playground environment.
120-
*
121-
* @return void
122-
*/
123-
public function show_onboarding() {
124-
$this->toggle_onboarding( 'show' );
97+
\wp_send_json_success( [ 'message' => \esc_html__( 'Onboarding shown successfully', 'progress-planner' ) ] );
12598
}
12699

127100
/**
@@ -135,10 +108,7 @@ public function show_header_notice() {
135108
return;
136109
}
137110

138-
$show_onboarding = \get_option( 'progress_planner_force_show_onboarding', false );
139-
$button_text = $show_onboarding ? \__( 'Hide onboarding', 'progress-planner' ) : \__( 'Show onboarding', 'progress-planner' );
140-
$action = $show_onboarding ? 'hide' : 'show';
141-
$nonce = \wp_create_nonce( "progress_planner_{$action}_onboarding" );
111+
$nonce = \wp_create_nonce( 'progress_planner_show_onboarding' );
142112
?>
143113

144114
<div class="prpl-widget-wrapper prpl-top-notice" id="prpl-playground-notice">
@@ -150,16 +120,16 @@ public function show_header_notice() {
150120
<div class="inner-content">
151121
<h1><?php \esc_html_e( 'Progress Planner demo', 'progress-planner' ); ?></h1>
152122

153-
<button id="progress-planner-toggle-onboarding" class="prpl-button-primary" style="margin-top: 20px; width:250px; float:right;">
154-
<?php echo \esc_html( $button_text ); ?>
123+
<button id="progress-planner-show-onboarding" class="prpl-button-primary" style="margin-top: 20px; width:250px; float:right;">
124+
<?php \esc_html_e( 'Show onboarding', 'progress-planner' ); ?>
155125
</button>
156126

157127
<p style="max-width:680px;">
158128
<?php \esc_html_e( 'This is a demo of Progress Planner. We\'ve prefilled this site with some content to show you what the reports in Progress Planner look like. We\'ve also added a few to-do\'s for you, you can see these here and on your dashoard.', 'progress-planner' ); ?>
159129
</p>
160130
<script>
161-
document.getElementById( 'progress-planner-toggle-onboarding' ).addEventListener( 'click', function() {
162-
const request = wp.ajax.post( 'progress_planner_<?php echo \esc_attr( $action ); ?>_onboarding', {
131+
document.getElementById( 'progress-planner-show-onboarding' ).addEventListener( 'click', function() {
132+
const request = wp.ajax.post( 'progress_planner_show_onboarding', {
163133
_ajax_nonce: '<?php echo \esc_attr( $nonce ); ?>',
164134
} );
165135
request.done( () => {

0 commit comments

Comments
 (0)