'; echo '

Welcome to AI Search!

'; echo '

Thank you for installing AI Search! Let\'s set up your intelligent search system in just a few minutes.

'; echo '

Start Setup Wizard '; echo 'Skip for Now

'; echo ''; } /** * Enqueue wizard scripts */ public function enqueue_scripts( $hook ) { // Only enqueue on admin pages if ( ! get_option( 'ai_search_show_setup_wizard', false ) ) { return; } wp_add_inline_script( 'jquery', ' jQuery(document).ready(function($) { $(".ai-search-dismiss-setup").on("click", function(e) { e.preventDefault(); $.post(ajaxurl, { action: "ai_search_dismiss_wizard", nonce: "' . wp_create_nonce( 'ai_search_dismiss_wizard' ) . '" }); $(".ai-search-setup-notice").fadeOut(); }); }); ' ); // Add AJAX handler for dismissing wizard add_action( 'wp_ajax_ai_search_dismiss_wizard', function() { check_ajax_referer( 'ai_search_dismiss_wizard', 'nonce' ); delete_option( 'ai_search_show_setup_wizard' ); update_option( 'ai_search_setup_completed', true ); wp_die(); }); } /** * Display setup wizard page */ public function display_wizard_page() { // Handle wizard completion if ( isset( $_GET['completed'] ) && $_GET['completed'] === 'true' ) { delete_option( 'ai_search_show_setup_wizard' ); update_option( 'ai_search_setup_completed', true ); $this->display_completion_page(); return; } $step = isset( $_GET['step'] ) ? intval( $_GET['step'] ) : 1; echo '
'; echo '

AI Search Setup Wizard

'; // Progress indicator echo '
'; echo '
'; echo '
'; echo '
'; echo '

Step ' . $step . ' of 3

'; echo '
'; if ( $step === 1 ) { include plugin_dir_path( __FILE__ ) . 'views/wizard/step-welcome.php'; } elseif ( $step === 2 ) { include plugin_dir_path( __FILE__ ) . 'views/wizard/step-provider.php'; } elseif ( $step === 3 ) { include plugin_dir_path( __FILE__ ) . 'views/wizard/step-final.php'; } // Wizard styles $this->output_wizard_styles(); echo '
'; } /** * Display completion page */ private function display_completion_page() { include plugin_dir_path( __FILE__ ) . 'views/wizard/completion.php'; } /** * Complete setup wizard */ public function complete_setup() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( __( 'Unauthorized access', 'ai-search' ) ); } check_admin_referer( 'ai_search_complete_setup' ); // Save settings $provider = sanitize_text_field( $_POST['provider'] ?? 'ai_service' ); $api_key = sanitize_text_field( $_POST['api_key'] ?? '' ); $similarity_threshold = floatval( $_POST['similarity_threshold'] ?? 0.65 ); update_option( 'ai_search_provider', $provider ); update_option( 'ai_search_api_key', $api_key ); update_option( 'ai_search_similarity_threshold', $similarity_threshold ); // Handle AI service registration if ( $provider === 'ai_service' ) { $service_client = new AI_Search_Service(); $service_token = $service_client->register_origin(); if ( $service_token ) { update_option( 'ai_search_service_token', $service_token ); } } // Setup WooCommerce if enabled if ( isset( $_POST['enable_woocommerce'] ) && class_exists( 'WooCommerce' ) ) { update_option( 'ai_search_woocommerce_fields', [ 'product_description', 'product_short_description', 'product_categories', 'product_tags' ]); } // Generate initial embeddings if requested if ( isset( $_POST['generate_initial_embeddings'] ) ) { $this->generate_initial_embeddings(); } // Mark setup as complete delete_option( 'ai_search_show_setup_wizard' ); // Also set a flag that setup was completed to prevent re-showing update_option( 'ai_search_setup_completed', true ); wp_redirect( admin_url( 'options-general.php?page=ai-search&setup=wizard&completed=true' ) ); exit; } /** * Generate initial embeddings during setup */ private function generate_initial_embeddings() { $posts = get_posts([ 'numberposts' => 50, 'post_status' => 'publish', 'meta_query' => [ [ 'key' => '_ai_search_embedding', 'compare' => 'NOT EXISTS' ] ] ]); // Get AI_Search instance to use generate_embedding method $ai_search = AI_Search::get_instance(); foreach ( $posts as $post ) { $ai_search->generate_embedding( $post->ID ); } } /** * Output wizard styles */ private function output_wizard_styles() { echo ''; } }