title. Add-ons can add their own steps before the last one $steps = array( 'welcome' => __( 'Welcome', 'velischat' ), 'api_key' => __( 'AI service', 'velischat' ), 'settings' => __( 'Initial settings', 'velischat' ), 'instructions' => __( 'Instructions', 'velischat' ), ); $steps = (array) apply_filters( 'velischat_wizard_steps', $steps ); $steps[ 'test_mode' ] = __( 'Test mode', 'velischat' ); return $steps; } function velischat_get_wizard_url( $step = '' ){ // Return the wizard page URL, optionally at a given step $url = admin_url( 'admin.php?page=velischat-wizard' ); if( $step !== '' ){ $url = add_query_arg( 'step', $step, $url ); } return $url; } function velischat_get_next_wizard_step( $step ){ // Return the step after the given one, or 'done' after the last step $keys = array_keys( velischat_get_wizard_steps() ); $index = array_search( $step, $keys, true ); if( $index === false || ! isset( $keys[ $index + 1 ] ) ){ return 'done'; } return $keys[ $index + 1 ]; } function velischat_get_previous_wizard_step( $step ){ // Return the step before the given one, or an empty string on the first step $keys = array_keys( velischat_get_wizard_steps() ); $index = array_search( $step, $keys, true ); if( ! $index ){ return ''; } return $keys[ $index - 1 ]; } function velischat_get_wizard_warnings(){ // Important settings still missing after the wizard (e.g. skipped steps): message => link to fix them $warnings = array(); $ai_status = velischat_get_ai_status(); if( $ai_status !== 'ready' ){ /* translators: %s: what to do, e.g. "To use ChatGPT, enter your OpenAI API key in Settings → Connectors." */ $warnings[ sprintf( __( 'The AI service isn\'t connected: without it the chatbot can\'t answer and visitors can\'t see it. %s', 'velischat' ), velischat_get_ai_status_text( $ai_status ) ) ] = velischat_get_wizard_url( 'api_key' ); } if( ! velischat_has_contact_email() ){ $warnings[ __( 'The email for contact requests is missing: until you set it, visitors can\'t see the chatbot.', 'velischat' ) ] = velischat_get_wizard_url( 'settings' ); } if( ! get_option( 'velischat_privacy_policy_url', '' ) && ! get_privacy_policy_url() ){ $warnings[ __( 'The privacy policy link is missing: visitors must be able to read it before writing in the chat.', 'velischat' ) ] = velischat_get_wizard_url( 'settings' ); } if( ! velischat_has_instructions() ){ $warnings[ __( 'The chatbot has no instructions yet: until you give it some, visitors can\'t see it.', 'velischat' ) ] = velischat_get_wizard_url( 'instructions' ); } return $warnings; } function velischat_save_wizard_step(){ // Save the data of the submitted wizard step and move to the next one if( ! current_user_can( 'manage_options' ) ){ wp_die( esc_html__( 'You don\'t have permission to do this.', 'velischat' ) ); } check_admin_referer( 'velischat_save_wizard' ); $step = isset( $_POST[ 'step' ] ) ? sanitize_key( wp_unslash( $_POST[ 'step' ] ) ) : ''; if( $step === 'api_key' ){ // The chosen service: its API key is entered in Settings > Connectors. Until it's connected the step stays // here, saying what's missing (the wizard can still skip it) $provider = velischat_sanitize_ai_provider( isset( $_POST[ 'velischat_ai_provider' ] ) ? sanitize_key( wp_unslash( $_POST[ 'velischat_ai_provider' ] ) ) : velischat_get_ai_provider() ); update_option( 'velischat_ai_provider', $provider ); if( ! velischat_ai_is_ready() ){ wp_safe_redirect( add_query_arg( 'velischat_status', 'not_connected', velischat_get_wizard_url( $step ) ) . '#velischat-ai-not-connected' ); exit; } } elseif( $step === 'settings' ){ $email = isset( $_POST[ 'velischat_contact_email' ] ) ? sanitize_email( wp_unslash( $_POST[ 'velischat_contact_email' ] ) ) : ''; if( ! is_email( $email ) ){ wp_safe_redirect( add_query_arg( 'velischat_status', 'invalid_email', velischat_get_wizard_url( $step ) ) ); exit; } update_option( 'velischat_contact_email', $email ); update_option( 'velischat_privacy_policy_url', isset( $_POST[ 'velischat_privacy_policy_url' ] ) ? esc_url_raw( wp_unslash( $_POST[ 'velischat_privacy_policy_url' ] ) ) : '' ); } elseif( $step === 'instructions' ){ velischat_save_contents_fields(); velischat_generate_context(); } elseif( $step === 'test_mode' ){ update_option( 'velischat_test_mode', velischat_sanitize_checkbox( ! empty( $_POST[ 'velischat_test_mode' ] ) ) ); } // Add-ons save the fields they added to this step, or their own step do_action( 'velischat_save_wizard_step', $step ); wp_safe_redirect( velischat_get_wizard_url( velischat_get_next_wizard_step( $step ) ) ); exit; } add_action( 'admin_post_velischat_save_wizard', 'velischat_save_wizard_step' ); function velischat_render_wizard_actions( $step ){ // Print the Back / Skip / Next buttons of a wizard step form; skipping moves on without saving $next = velischat_get_next_wizard_step( $step ); $is_last = $next === 'done'; ?>
    $title ){ ?>

👋

    $url ){ ?>