diff --git a/assets/js/onboarding/onboarding.js b/assets/js/onboarding/onboarding.js index 0d93ac074..3bda0afeb 100644 --- a/assets/js/onboarding/onboarding.js +++ b/assets/js/onboarding/onboarding.js @@ -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 { diff --git a/classes/class-onboard-wizard.php b/classes/class-onboard-wizard.php index 1b50183dc..80a79eede 100644 --- a/classes/class-onboard-wizard.php +++ b/classes/class-onboard-wizard.php @@ -12,6 +12,13 @@ */ class Onboard_Wizard { + /** + * Option name for storing onboarding progress. + * + * @var string + */ + public const PROGRESS_OPTION_NAME = 'prpl_onboard_progress'; + /** * Steps and their order. * @@ -19,13 +26,22 @@ class Onboard_Wizard { */ 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. } /** @@ -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; /** @@ -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; } @@ -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' ) ] ); } diff --git a/classes/utils/class-debug-tools.php b/classes/utils/class-debug-tools.php index 54aae8a21..6b42a5ca6 100644 --- a/classes/utils/class-debug-tools.php +++ b/classes/utils/class-debug-tools.php @@ -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' ); diff --git a/classes/utils/class-playground.php b/classes/utils/class-playground.php index 988043db8..130a00431 100644 --- a/classes/utils/class-playground.php +++ b/classes/utils/class-playground.php @@ -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', [ @@ -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' ) ); @@ -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' ) ] ); } /** @@ -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' ); ?>