Changeset 3472845
- Timestamp:
- 03/02/2026 03:13:31 PM (4 weeks ago)
- Location:
- ai-search
- Files:
-
- 35 added
- 4 edited
-
tags/1.22.0 (added)
-
tags/1.22.0/admin (added)
-
tags/1.22.0/admin/class-admin-manager.php (added)
-
tags/1.22.0/admin/class-post-meta-box.php (added)
-
tags/1.22.0/admin/class-quota-manager.php (added)
-
tags/1.22.0/admin/class-settings-pages.php (added)
-
tags/1.22.0/admin/class-setup-wizard.php (added)
-
tags/1.22.0/admin/css (added)
-
tags/1.22.0/admin/css/admin-settings.css (added)
-
tags/1.22.0/admin/views (added)
-
tags/1.22.0/admin/views/components (added)
-
tags/1.22.0/admin/views/components/cpt-taxonomy-selector.php (added)
-
tags/1.22.0/admin/views/components/hybrid-balance-slider.php (added)
-
tags/1.22.0/admin/views/components/threshold-slider.php (added)
-
tags/1.22.0/admin/views/settings-cache.php (added)
-
tags/1.22.0/admin/views/settings-custom-fields.php (added)
-
tags/1.22.0/admin/views/settings-embeddings.php (added)
-
tags/1.22.0/admin/views/settings-general.php (added)
-
tags/1.22.0/admin/views/settings-quota.php (added)
-
tags/1.22.0/admin/views/settings-search-config.php (added)
-
tags/1.22.0/admin/views/settings-woocommerce.php (added)
-
tags/1.22.0/admin/views/wizard (added)
-
tags/1.22.0/admin/views/wizard/completion.php (added)
-
tags/1.22.0/admin/views/wizard/step-custom-fields.php (added)
-
tags/1.22.0/admin/views/wizard/step-final.php (added)
-
tags/1.22.0/admin/views/wizard/step-provider.php (added)
-
tags/1.22.0/admin/views/wizard/step-welcome.php (added)
-
tags/1.22.0/ai-search.php (added)
-
tags/1.22.0/assets (added)
-
tags/1.22.0/assets/icon.svg (added)
-
tags/1.22.0/includes (added)
-
tags/1.22.0/includes/class-ai-search-service.php (added)
-
tags/1.22.0/includes/class-rest-api.php (added)
-
tags/1.22.0/languages (added)
-
tags/1.22.0/readme.txt (added)
-
trunk/admin/class-admin-manager.php (modified) (3 diffs)
-
trunk/ai-search.php (modified) (1 diff)
-
trunk/includes/class-ai-search-service.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ai-search/trunk/admin/class-admin-manager.php
r3464286 r3472845 60 60 add_action( 'admin_menu', [ $this, 'register_settings_menu' ] ); 61 61 add_action( 'admin_notices', [ $this->setup_wizard, 'show_setup_notice' ] ); 62 add_action( 'admin_notices', [ $this, 'show_domain_mismatch_notice' ] ); 62 63 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] ); 63 64 add_action( 'admin_enqueue_scripts', [ $this->setup_wizard, 'enqueue_scripts' ] ); … … 75 76 add_action( 'admin_post_ai_search_refresh_quota', [ $this->settings_pages, 'refresh_quota_data' ] ); 76 77 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' ] ); 77 79 78 80 // AJAX actions … … 286 288 return $submenu_file; 287 289 } 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 } 288 400 } -
ai-search/trunk/ai-search.php
r3464286 r3472845 1 1 <?php 2 2 /** 3 * Plugin Name: AI Search 3 * Plugin Name: AI Search - Intelligent Search for WooCommerce and WordPress 4 4 * Description: Replaces the default search with an intelligent search system. 5 * Version: 1.2 1.05 * Version: 1.22.0 6 6 * Author: Samuel Silva 7 7 * Author URI: https://samuelsilva.pt -
ai-search/trunk/includes/class-ai-search-service.php
r3443528 r3472845 33 33 if ( isset( $body['api_token'] ) ) { 34 34 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() ); 35 37 return $body['api_token']; 36 38 } 37 39 38 40 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', '' ); 39 82 } 40 83 -
ai-search/trunk/readme.txt
r3464286 r3472845 1 === AI Search ===1 === AI Search - Intelligent Search for WooCommerce and WordPress === 2 2 Contributors: samuelsilvapt 3 3 Tags: search, AI, semantic search, WooCommerce, ecommerce, product search, smart search, OpenAI 4 4 Tested up to: 6.8 5 Stable tag: 1.2 1.05 Stable tag: 1.22.0 6 6 Requires PHP: 8.0 7 7 License: GPLv2 … … 122 122 123 123 == 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) 124 130 125 131 = 1.21.0 =
Note: See TracChangeset
for help on using the changeset viewer.