Plugin Directory

Changeset 3472845


Ignore:
Timestamp:
03/02/2026 03:13:31 PM (4 weeks ago)
Author:
samuelsilvapt
Message:

AI Search 1.22.0

Location:
ai-search
Files:
35 added
4 edited

Legend:

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

    r3464286 r3472845  
    6060        add_action( 'admin_menu', [ $this, 'register_settings_menu' ] );
    6161        add_action( 'admin_notices', [ $this->setup_wizard, 'show_setup_notice' ] );
     62        add_action( 'admin_notices', [ $this, 'show_domain_mismatch_notice' ] );
    6263        add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
    6364        add_action( 'admin_enqueue_scripts', [ $this->setup_wizard, 'enqueue_scripts' ] );
     
    7576        add_action( 'admin_post_ai_search_refresh_quota', [ $this->settings_pages, 'refresh_quota_data' ] );
    7677        add_action( 'admin_post_ai_search_complete_setup', [ $this->setup_wizard, 'complete_setup' ] );
     78        add_action( 'admin_post_ai_search_reconnect_service', [ $this, 'reconnect_service' ] );
    7779
    7880        // AJAX actions
     
    286288        return $submenu_file;
    287289    }
     290
     291    /**
     292     * Show admin notice when domain doesn't match registered origin.
     293     */
     294    public function show_domain_mismatch_notice() {
     295        // Only show to admins
     296        if ( ! current_user_can( 'manage_options' ) ) {
     297            return;
     298        }
     299
     300        // Only check if using AI Search Service (not OpenAI)
     301        $provider = get_option( 'ai_search_provider', 'ai_service' );
     302        if ( $provider !== 'ai_service' ) {
     303            return;
     304        }
     305
     306        // Check if token exists
     307        $service_token = get_option( 'ai_search_service_token' );
     308        if ( empty( $service_token ) ) {
     309            return;
     310        }
     311
     312        // Check if reconnection was successful
     313        if ( isset( $_GET['ai_search_reconnected'] ) && $_GET['ai_search_reconnected'] === 'success' ) {
     314            ?>
     315            <div class="notice notice-success is-dismissible">
     316                <p>
     317                    <strong><?php esc_html_e( 'AI Search', 'ai-search' ); ?>:</strong>
     318                    <?php esc_html_e( 'Successfully reconnected to AI Search Service with the new domain.', 'ai-search' ); ?>
     319                </p>
     320            </div>
     321            <?php
     322            return;
     323        }
     324
     325        if ( isset( $_GET['ai_search_reconnected'] ) && $_GET['ai_search_reconnected'] === 'error' ) {
     326            ?>
     327            <div class="notice notice-error is-dismissible">
     328                <p>
     329                    <strong><?php esc_html_e( 'AI Search', 'ai-search' ); ?>:</strong>
     330                    <?php esc_html_e( 'Failed to reconnect to AI Search Service. Please try again or contact support.', 'ai-search' ); ?>
     331                </p>
     332            </div>
     333            <?php
     334            return;
     335        }
     336
     337        $service = new AI_Search_Service();
     338        if ( $service->check_origin_match() ) {
     339            return;
     340        }
     341
     342        $registered_origin = $service->get_registered_origin();
     343        $current_origin = get_site_url();
     344        $reconnect_url = wp_nonce_url(
     345            admin_url( 'admin-post.php?action=ai_search_reconnect_service' ),
     346            'ai_search_reconnect_service'
     347        );
     348        ?>
     349        <div class="notice notice-warning">
     350            <p>
     351                <strong><?php esc_html_e( 'AI Search - Domain Mismatch Detected', 'ai-search' ); ?></strong>
     352            </p>
     353            <p>
     354                <?php
     355                printf(
     356                    /* translators: 1: registered domain, 2: current domain */
     357                    esc_html__( 'Your AI Search Service token was registered for %1$s but your site is now running on %2$s. This may cause the search to fail.', 'ai-search' ),
     358                    '<code>' . esc_html( $registered_origin ) . '</code>',
     359                    '<code>' . esc_html( $current_origin ) . '</code>'
     360                );
     361                ?>
     362            </p>
     363            <p>
     364                <a href="<?php echo esc_url( $reconnect_url ); ?>" class="button button-primary">
     365                    <?php esc_html_e( 'Reconnect with Current Domain', 'ai-search' ); ?>
     366                </a>
     367                <span class="description" style="margin-left: 10px;">
     368                    <?php esc_html_e( 'This will register a new token for the current domain.', 'ai-search' ); ?>
     369                </span>
     370            </p>
     371        </div>
     372        <?php
     373    }
     374
     375    /**
     376     * Handle service reconnection.
     377     */
     378    public function reconnect_service() {
     379        if ( ! current_user_can( 'manage_options' ) ) {
     380            wp_die( __( 'Unauthorized access', 'ai-search' ) );
     381        }
     382
     383        check_admin_referer( 'ai_search_reconnect_service' );
     384
     385        // Clear old token and origin
     386        delete_option( 'ai_search_service_token' );
     387        delete_option( 'ai_search_registered_origin' );
     388
     389        // Register new token
     390        $service = new AI_Search_Service();
     391        $new_token = $service->register_origin();
     392
     393        if ( $new_token ) {
     394            wp_redirect( admin_url( 'admin.php?page=ai-search&ai_search_reconnected=success' ) );
     395        } else {
     396            wp_redirect( admin_url( 'admin.php?page=ai-search&ai_search_reconnected=error' ) );
     397        }
     398        exit;
     399    }
    288400}
  • ai-search/trunk/ai-search.php

    r3464286 r3472845  
    11<?php
    22/**
    3  * Plugin Name: AI Search
     3 * Plugin Name: AI Search - Intelligent Search for WooCommerce and WordPress
    44 * Description: Replaces the default search with an intelligent search system.
    5  * Version: 1.21.0
     5 * Version: 1.22.0
    66 * Author: Samuel Silva
    77 * Author URI: https://samuelsilva.pt
  • ai-search/trunk/includes/class-ai-search-service.php

    r3443528 r3472845  
    3333        if ( isset( $body['api_token'] ) ) {
    3434            update_option( 'ai_search_service_token', sanitize_text_field( $body['api_token'] ) );
     35            // Store the registered origin for mismatch detection
     36            update_option( 'ai_search_registered_origin', get_site_url() );
    3537            return $body['api_token'];
    3638        }
    3739
    3840        return false;
     41    }
     42
     43    /**
     44     * Check if the current site URL matches the registered origin.
     45     *
     46     * @return bool True if origins match or no token exists, false if mismatch
     47     */
     48    public function check_origin_match() {
     49        $service_token = get_option( 'ai_search_service_token' );
     50        if ( empty( $service_token ) ) {
     51            return true; // No token, no mismatch
     52        }
     53
     54        $registered_origin = get_option( 'ai_search_registered_origin', '' );
     55        if ( empty( $registered_origin ) ) {
     56            // Legacy: token exists but no stored origin, validate via API
     57            $validation = $this->validate_token();
     58            if ( $validation && isset( $validation['origin'] ) ) {
     59                update_option( 'ai_search_registered_origin', $validation['origin'] );
     60                $registered_origin = $validation['origin'];
     61            } else {
     62                return true; // Can't determine, assume OK
     63            }
     64        }
     65
     66        $current_origin = get_site_url();
     67
     68        // Normalize URLs for comparison (remove trailing slashes, compare hosts)
     69        $registered_host = wp_parse_url( $registered_origin, PHP_URL_HOST );
     70        $current_host = wp_parse_url( $current_origin, PHP_URL_HOST );
     71
     72        return $registered_host === $current_host;
     73    }
     74
     75    /**
     76     * Get the registered origin.
     77     *
     78     * @return string The registered origin URL
     79     */
     80    public function get_registered_origin() {
     81        return get_option( 'ai_search_registered_origin', '' );
    3982    }
    4083
  • ai-search/trunk/readme.txt

    r3464286 r3472845  
    1 === AI Search ===
     1=== AI Search - Intelligent Search for WooCommerce and WordPress ===
    22Contributors: samuelsilvapt
    33Tags: search, AI, semantic search, WooCommerce, ecommerce, product search, smart search, OpenAI
    44Tested up to: 6.8
    5 Stable tag: 1.21.0
     5Stable tag: 1.22.0
    66Requires PHP: 8.0
    77License: GPLv2
     
    122122
    123123== Changelog ==
     124
     125= 1.22.0 =
     126- **Domain Mismatch Detection**: Admin warning when site domain differs from the registered AI Search Service domain
     127- **One-Click Reconnect**: Button to easily reconnect and get a new token for the current domain
     128- **Automatic Origin Tracking**: Plugin now stores the registered origin for future mismatch detection
     129- **Improved Migration Support**: Better handling when moving sites between domains (staging to production, domain changes)
    124130
    125131= 1.21.0 =
Note: See TracChangeset for help on using the changeset viewer.