Plugin Directory

Changeset 3441628


Ignore:
Timestamp:
01/17/2026 03:25:29 PM (2 months ago)
Author:
samuelsilvapt
Message:

1.12.0 v

Location:
ai-search
Files:
24 added
4 edited

Legend:

Unmodified
Added
Removed
  • ai-search/trunk/admin/class-setup-wizard.php

    r3419047 r3441628  
    218218    }
    219219   
    220     /**
    221      * Plugin activation handler
    222      */
    223     public static function activate_plugin() {
    224         // Set flag to show setup wizard
    225         update_option( 'ai_search_show_setup_wizard', true );
    226        
    227         // Set default settings
    228         add_option( 'ai_search_provider', 'ai_service' );
    229         add_option( 'ai_search_similarity_threshold', 0.5 );
    230        
    231         // Set activation redirect flag
    232         update_option( 'ai_search_activation_redirect', true );
    233     }
    234220}
  • ai-search/trunk/admin/views/settings-general.php

    r3434325 r3441628  
    1212$badge_public = get_option( 'ai_search_badge_public', false );
    1313
    14 // Handle token validation messages
     14// Handle connection check messages
    1515if ( isset( $_GET['token_validation'] ) ) {
    1616    $validation_status = sanitize_text_field( $_GET['token_validation'] );
    17    
     17
    1818    if ( $validation_status === 'success' ) {
    1919        $validation_data = get_transient( 'ai_search_validation_data' );
    2020        if ( $validation_data ) {
    21             echo '<div class="updated"><p><strong>Token Validation Successful!</strong></p>';
     21            echo '<div class="notice notice-success"><p><strong>Connection successful!</strong> AI Search Service is working correctly.</p>';
    2222            if ( isset( $validation_data['client'] ) ) {
    2323                $client = $validation_data['client'];
    24                 echo '<ul style="margin-left: 20px;">';
    25                 echo '<li><strong>Client ID:</strong> ' . esc_html( $client['id'] ?? 'N/A' ) . '</li>';
    26                 echo '<li><strong>Origin:</strong> ' . esc_html( $client['origin'] ?? 'N/A' ) . '</li>';
    27                 echo '<li><strong>Daily Limit:</strong> ' . esc_html( number_format( $client['daily_limit'] ?? 0 ) ) . '</li>';
    28                 echo '<li><strong>Total Limit:</strong> ' . esc_html( number_format( $client['total_limit'] ?? 0 ) ) . '</li>';
    29                 echo '<li><strong>Used Daily:</strong> ' . esc_html( number_format( $client['used_daily'] ?? 0 ) ) . '</li>';
    30                 echo '<li><strong>Used Total:</strong> ' . esc_html( number_format( $client['used_total'] ?? 0 ) ) . '</li>';
    31                 echo '<li><strong>Quotas Exceeded:</strong> ' . (
    32                     isset( $client['quotas_exceeded']['daily'] ) && $client['quotas_exceeded']['daily'] ? 'Daily' : ''
    33                 ) . (
    34                     isset( $client['quotas_exceeded']['total'] ) && $client['quotas_exceeded']['total'] ? ' Total' : ''
    35                 ) . (
    36                     !( $client['quotas_exceeded']['daily'] ?? false ) && !( $client['quotas_exceeded']['total'] ?? false ) ? 'None' : ''
    37                 ) . '</li>';
    38                 echo '</ul>';
     24                $used_total = intval( $client['used_total'] ?? 0 );
     25                $total_limit = intval( $client['total_limit'] ?? 10000 );
     26                $remaining = $total_limit - $used_total;
     27                echo '<p>Embeddings used: <strong>' . esc_html( number_format( $used_total ) ) . '</strong> / ' . esc_html( number_format( $total_limit ) ) . ' (' . esc_html( number_format( $remaining ) ) . ' remaining)</p>';
    3928            }
    4029            echo '</div>';
     
    4332    } elseif ( $validation_status === 'invalid' ) {
    4433        $error_data = get_transient( 'ai_search_validation_error' );
    45         echo '<div class="error"><p><strong>Token Validation Failed!</strong></p>';
     34        echo '<div class="notice notice-error"><p><strong>Connection failed!</strong></p>';
    4635        if ( $error_data && isset( $error_data['details'] ) ) {
    47             echo '<p>Error: ' . esc_html( $error_data['details'] ) . '</p>';
     36            echo '<p>' . esc_html( $error_data['details'] ) . '</p>';
    4837        }
    4938        echo '</div>';
    5039        delete_transient( 'ai_search_validation_error' );
    5140    } elseif ( $validation_status === 'error' ) {
    52         echo '<div class="error"><p><strong>Token Validation Error!</strong> Unable to connect to AI Search Service.</p></div>';
     41        echo '<div class="notice notice-error"><p><strong>Connection failed!</strong> Unable to reach AI Search Service. Please try again later.</p></div>';
    5342    } elseif ( $validation_status === 'no_token' ) {
    54         echo '<div class="error"><p><strong>No Token Found!</strong> Please save your settings first to generate a service token.</p></div>';
     43        echo '<div class="notice notice-warning"><p><strong>Not registered.</strong> Please save your settings to register with the AI Search Service.</p></div>';
    5544    }
    5645}
     
    6857    update_option( 'ai_search_similarity_threshold', floatval( $_POST['similarity_threshold'] ) );
    6958   
    70     // Save service token if provided
    71     if ( isset( $_POST['service_token'] ) ) {
    72         update_option( 'ai_search_service_token', sanitize_text_field( wp_unslash( $_POST['service_token'] ) ) );
    73     }
    74 
    7559    // Save badge public visibility option
    7660    update_option( 'ai_search_badge_public', isset( $_POST['badge_public'] ) && $_POST['badge_public'] === '1' );
     
    11195
    11296    <div id="service-token-container" style="display: <?php echo ( $provider === 'ai_service' ? 'block' : 'none' ); ?>;">
    113         <label for="service_token">AI Search Service Token:</label><br>
    114         <input type="text" id="service_token" name="service_token" value="<?php echo esc_attr( $service_token ); ?>" style="width: 100%; max-width: 400px;" />
    115         <p><em>This token is automatically generated when you select the AI Service. You can manually update it if needed.</em></p>
    116        
    11797        <?php if ( ! empty( $service_token ) ) : ?>
    118         <div style="margin-top: 10px;">
    119             <button type="button" id="validate-token-btn" class="button button-secondary">Validate Token</button>
    120             <span id="validation-spinner" style="display: none; margin-left: 10px;">Validating...</span>
    121             <p><em>Click to validate your token and check usage statistics.</em></p>
     98        <div class="ai-search-connection-status" style="background: #f0f6fc; padding: 15px; border-radius: 4px; border-left: 4px solid #2271b1;">
     99            <p style="margin: 0 0 10px 0;"><strong>Status:</strong> Registered with AI Search Service</p>
     100            <button type="button" id="check-connection-btn" class="button button-secondary">Check Connection</button>
     101            <span id="connection-spinner" style="display: none; margin-left: 10px;">Checking...</span>
     102        </div>
     103        <?php else : ?>
     104        <div class="ai-search-connection-status" style="background: #fff3cd; padding: 15px; border-radius: 4px; border-left: 4px solid #856404;">
     105            <p style="margin: 0;"><strong>Status:</strong> Not registered. Save settings to register automatically.</p>
    122106        </div>
    123107        <?php endif; ?>
     
    359343    }
    360344   
    361     var validateBtn = document.getElementById("validate-token-btn");
    362     if (validateBtn) {
    363         validateBtn.addEventListener("click", function() {
    364             var spinner = document.getElementById("validation-spinner");
    365             validateBtn.disabled = true;
     345    var checkConnectionBtn = document.getElementById("check-connection-btn");
     346    if (checkConnectionBtn) {
     347        checkConnectionBtn.addEventListener("click", function() {
     348            var spinner = document.getElementById("connection-spinner");
     349            checkConnectionBtn.disabled = true;
    366350            spinner.style.display = "inline";
    367            
     351
    368352            // Create a form and submit it
    369353            var form = document.createElement("form");
    370354            form.method = "POST";
    371355            form.action = "<?php echo esc_url( admin_url( 'admin-post.php?action=ai_search_validate_token' ) ); ?>";
    372            
     356
    373357            var nonceField = document.createElement("input");
    374358            nonceField.type = "hidden";
    375359            nonceField.name = "_wpnonce";
    376360            nonceField.value = "<?php echo wp_create_nonce( 'ai_search_validate_token' ); ?>";
    377            
     361
    378362            form.appendChild(nonceField);
    379363            document.body.appendChild(form);
  • ai-search/trunk/ai-search.php

    r3434325 r3441628  
    33 * Plugin Name: AI Search
    44 * Description: Replaces the default search with an intelligent search system.
    5  * Version: 1.11.0
     5 * Version: 1.12.0
    66 * Author: Samuel Silva
    77 * Author URI: https://samuelsilva.pt
     
    1717
    1818// Define plugin constants
    19 define( 'AI_SEARCH_VERSION', '1.11.0' );
     19define( 'AI_SEARCH_VERSION', '1.12.0' );
    2020define( 'AI_SEARCH_PATH', plugin_dir_path( __FILE__ ) );
    2121define( 'AI_SEARCH_URL', plugin_dir_url( __FILE__ ) );
     
    3939     * Plugin version.
    4040     */
    41     const VERSION = '1.11.0';
     41    const VERSION = '1.12.0';
    4242
    4343    /**
     
    787787
    788788// Plugin activation hook
    789 register_activation_hook( __FILE__, function() {
     789register_activation_hook( __FILE__, 'ai_search_activate_plugin' );
     790
     791/**
     792 * Plugin activation handler.
     793 */
     794function ai_search_activate_plugin() {
    790795    // Set default settings
    791796    add_option( 'ai_search_provider', 'ai_service' );
    792797    add_option( 'ai_search_similarity_threshold', 0.5 );
    793 } );
     798
     799    // Set flag to show setup wizard
     800    update_option( 'ai_search_show_setup_wizard', true );
     801
     802    // Register origin with AI Search Service immediately
     803    require_once plugin_dir_path( __FILE__ ) . 'includes/class-ai-search-service.php';
     804    $service_client = new AI_Search_Service();
     805    $service_token = $service_client->register_origin();
     806    if ( $service_token ) {
     807        update_option( 'ai_search_service_token', $service_token );
     808    }
     809
     810    // Set activation redirect flag
     811    set_transient( 'ai_search_activation_redirect', true, 30 );
     812}
     813
     814// Handle activation redirect
     815add_action( 'admin_init', 'ai_search_activation_redirect' );
     816
     817/**
     818 * Redirect to setup wizard after plugin activation.
     819 */
     820function ai_search_activation_redirect() {
     821    // Check if we should redirect
     822    if ( ! get_transient( 'ai_search_activation_redirect' ) ) {
     823        return;
     824    }
     825
     826    // Delete the transient so we don't redirect again
     827    delete_transient( 'ai_search_activation_redirect' );
     828
     829    // Don't redirect if activating multiple plugins or doing bulk action
     830    if ( isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) {
     831        return;
     832    }
     833
     834    // Don't redirect if setup was already completed
     835    if ( get_option( 'ai_search_setup_completed', false ) ) {
     836        return;
     837    }
     838
     839    // Redirect to setup wizard
     840    wp_safe_redirect( admin_url( 'options-general.php?page=ai-search&setup=wizard' ) );
     841    exit;
     842}
    794843
    795844// Initialize the plugin.
  • ai-search/trunk/readme.txt

    r3434325 r3441628  
    33Tags: search, AI, semantic search, WooCommerce, ecommerce, product search, smart search, OpenAI
    44Tested up to: 6.8
    5 Stable tag: 1.11.0
     5Stable tag: 1.12.0
    66Requires PHP: 8.0
    77License: GPLv2
     
    8787
    8888== Changelog ==
     89
     90= 1.12.0 =
     91- **Automatic Service Registration**: Plugin now registers with AI Search Service immediately on activation
     92- **Setup Wizard Redirect**: Users are automatically redirected to the setup wizard after plugin activation
     93- **Simplified Settings UI**: Removed service token field from settings - connection is now managed automatically
     94- **Check Connection Button**: Replaced "Validate Token" with cleaner "Check Connection" button showing usage stats
     95- **Streamlined Onboarding**: Better first-time user experience with automatic configuration
     96- **Code Cleanup**: Removed unused spelling suggestions and search highlighter classes
    8997
    9098= 1.11.0 =
Note: See TracChangeset for help on using the changeset viewer.