Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions assets/js/onboarding/onboarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,17 @@ class ProgressPlannerOnboardWizard {
this.state.data.finished =
this.state.currentStep === this.tourSteps.length - 1;
this.closeTour();

// If on PP Dashboard page and privacy was accepted during onboarding,
// refresh the page to properly initialize dashboard components.
if (
this.state.data.privacyAccepted &&
window.location.href.includes(
'admin.php?page=progress-planner'
)
) {
window.location.reload();
}
} );
}
} else {
Expand Down
24 changes: 20 additions & 4 deletions classes/class-onboard-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,36 @@
*/
class Onboard_Wizard {

/**
* Option name for storing onboarding progress.
*
* @var string
*/
public const PROGRESS_OPTION_NAME = 'prpl_onboard_progress';

/**
* Steps and their order.
*
* @var array
*/
protected $steps = [];

/**
* Delete the onboarding progress option.
*
* @return bool True if the option was deleted, false otherwise.
*/
public static function delete_progress() {
return \delete_option( self::PROGRESS_OPTION_NAME );
}

/**
* Constructor.
*
* @return void
*/
public function __construct() {
\add_action( 'init', [ $this, 'maybe_register_popover_hooks' ], 0 );
\add_action( 'init', [ $this, 'maybe_register_popover_hooks' ], 10 ); // Wait for the Playground to register its hooks.
}

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

/**
Expand Down Expand Up @@ -319,7 +335,7 @@ protected function get_saved_progress() {
return null;
}

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

// Save as user meta?
\update_option( 'prpl_onboard_progress', $progress );
\update_option( self::PROGRESS_OPTION_NAME, $progress );

\wp_send_json_success( [ 'message' => \esc_html__( 'Tour progress saved.', 'progress-planner' ) ] );
}
Expand Down
2 changes: 1 addition & 1 deletion classes/utils/class-debug-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ public function check_delete_onboarding_progress() {
$this->verify_nonce();

// Delete the onboarding progress.
\delete_option( 'prpl_onboard_progress' );
\Progress_Planner\Onboard_Wizard::delete_progress();

// Delete the license key.
\delete_option( 'progress_planner_license_key' );
Expand Down
56 changes: 13 additions & 43 deletions classes/utils/class-playground.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function register_hooks() {
if ( ! \progress_planner()->get_license_key() && ! \get_option( 'progress_planner_demo_data_generated', false ) ) {
$this->generate_data();
\update_option( 'progress_planner_license_key', \str_replace( ' ', '-', $this->create_random_string( 20 ) ) );
\update_option( 'progress_planner_force_show_onboarding', false );
\update_option(
'progress_planner_todo',
[
Expand All @@ -48,7 +47,6 @@ public function register_hooks() {
\update_option( 'progress_planner_demo_data_generated', true );
}
\add_action( 'progress_planner_admin_page_header_before', [ $this, 'show_header_notice' ] );
\add_action( 'wp_ajax_progress_planner_hide_onboarding', [ $this, 'hide_onboarding' ] );
\add_action( 'wp_ajax_progress_planner_show_onboarding', [ $this, 'show_onboarding' ] );

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

/**
* Toggle the onboarding visibility in the Playground environment.
*
* @param string $action Either 'show' or 'hide'.
* Show the onboarding in the Playground environment.
*
* @return void
*/
private function toggle_onboarding( $action ) {
$nonce_action = "progress_planner_{$action}_onboarding";
\check_ajax_referer( $nonce_action, 'nonce' );
public function show_onboarding() {
\check_ajax_referer( 'progress_planner_show_onboarding', 'nonce' );

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

if ( $action === 'hide' ) {
\add_option( 'progress_planner_license_key', \str_replace( ' ', '-', $this->create_random_string( 20 ) ) );
$message = \esc_html__( 'Onboarding hidden successfully', 'progress-planner' );
} else {
\delete_option( 'progress_planner_license_key' );
$message = \esc_html__( 'Onboarding shown successfully', 'progress-planner' );
}
\update_option( 'progress_planner_force_show_onboarding', $action !== 'hide' );

\wp_send_json_success( [ 'message' => $message ] );
}

/**
* Hide the onboarding in the Playground environment.
*
* @return void
*/
public function hide_onboarding() {
$this->toggle_onboarding( 'hide' );
}
// Delete onboarding progress to trigger fresh onboarding.
\Progress_Planner\Onboard_Wizard::delete_progress();
// Delete the license key to trigger onboarding (privacy not accepted).
\delete_option( 'progress_planner_license_key' );

/**
* Show the onboarding in the Playground environment.
*
* @return void
*/
public function show_onboarding() {
$this->toggle_onboarding( 'show' );
\wp_send_json_success( [ 'message' => \esc_html__( 'Onboarding shown successfully', 'progress-planner' ) ] );
}

/**
Expand All @@ -135,10 +108,7 @@ public function show_header_notice() {
return;
}

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

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

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

<p style="max-width:680px;">
<?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' ); ?>
</p>
<script>
document.getElementById( 'progress-planner-toggle-onboarding' ).addEventListener( 'click', function() {
const request = wp.ajax.post( 'progress_planner_<?php echo \esc_attr( $action ); ?>_onboarding', {
document.getElementById( 'progress-planner-show-onboarding' ).addEventListener( 'click', function() {
const request = wp.ajax.post( 'progress_planner_show_onboarding', {
_ajax_nonce: '<?php echo \esc_attr( $nonce ); ?>',
} );
request.done( () => {
Expand Down
Loading