Changeset 3389096
- Timestamp:
- 11/03/2025 07:00:40 PM (5 months ago)
- Location:
- smartsearchwp/trunk
- Files:
-
- 5 edited
-
includes/config/wdgpt-config-general-settings.php (modified) (4 diffs)
-
includes/wdgpt-client.php (modified) (2 diffs)
-
includes/wdgpt-config.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
wdgpt.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
smartsearchwp/trunk/includes/config/wdgpt-config-general-settings.php
r3241701 r3389096 119 119 wdgpt_general_settings_save_options(); 120 120 } 121 122 // Handle purge transients action 123 if ( isset( $_POST['wdgpt_purge_transients'] ) && 124 isset( $_POST['wdgpt_settings_nonce'] ) && 125 wp_verify_nonce( sanitize_key( $_POST['wdgpt_settings_nonce'] ), 'wdgpt_settings' ) ) { 126 wdgpt_purge_transients(); 127 new WDGPT_Admin_Notices( 2, __( 'Transients purged successfully!', 'webdigit-chatbot' ) ); 128 } 121 129 ?> 122 130 <?php wp_nonce_field( 'wdgpt_settings', 'wdgpt_settings_nonce' ); ?> … … 237 245 </select> 238 246 <?php 239 $available_models = wdpgt_get_models( $models ); 247 // Safely get models - don't crash if API call fails 248 $available_models = array(); 249 try { 250 $available_models = wdpgt_get_models( $models ); 251 } catch ( \Exception $e ) { 252 // Silently fail - will show no available models 253 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 254 error_log( 'SmartSearchWP: Error in config getting models - ' . $e->getMessage() ); 255 } 256 } 240 257 $selected_model = get_option( 'wdgpt_model', '' ); 241 258 $selected_model_exists = false; 242 259 foreach ( $available_models as $model ) { 243 if ( $model['id'] === $selected_model ) {260 if ( isset( $model['id'] ) && $model['id'] === $selected_model ) { 244 261 $selected_model_exists = true; 245 262 break; … … 529 546 </td> 530 547 </tr> 548 <tr> 549 <th scope="row"> 550 <?php esc_html_e('Purge Transients', 'webdigit-chatbot'); ?> 551 </th> 552 <td> 553 <button type="submit" name="wdgpt_purge_transients" class="button button-secondary" onclick="return confirm('<?php echo esc_js( __( 'Are you sure you want to purge the transients cache?', 'webdigit-chatbot' ) ); ?>');"> 554 <?php esc_html_e('Purger les transient', 'webdigit-chatbot'); ?> 555 </button> 556 <p class="description"> 557 <?php 558 esc_html_e( 559 'Clear cached data for addons and other transient data. This will refresh the cache on the next page load.', 560 'webdigit-chatbot' 561 ); 562 ?> 563 </p> 564 </td> 565 </tr> 531 566 </table> 532 567 <input type='submit' name='submit' value=' … … 563 598 } 564 599 600 /** 601 * Purge transients cache. 602 * 603 * @return void 604 */ 605 function wdgpt_purge_transients() { 606 // Purge addons cache 607 delete_transient( 'wdgpt_addons_cache' ); 608 609 // Add more transients here as needed 610 // Example: delete_transient( 'wdgpt_other_cache' ); 611 } 612 565 613 566 614 ?> -
smartsearchwp/trunk/includes/wdgpt-client.php
r3308372 r3389096 50 50 */ 51 51 function wdgpt_is_api_down() { 52 $openai_api_key = get_option( 'wd_openai_api_key', '' ); 53 $openai_client = new OpenAI( $openai_api_key ); 54 $models = json_decode( $openai_client->listModels(), true ); 55 // Verification if the OpenAI API is down. 56 if ( isset( $models['error'] ) ) { 57 $bad_gateway = strpos( strtolower( $models['error']['message'] ), 'bad gateway' ); 58 if ( $bad_gateway !== false ) { 59 return true; 60 } 52 try { 53 $openai_api_key = get_option( 'wd_openai_api_key', '' ); 54 if ( empty( $openai_api_key ) ) { 55 return false; 56 } 57 $openai_client = new OpenAI( $openai_api_key ); 58 $response = $openai_client->listModels(); 59 if ( $response === false ) { 60 return false; 61 } 62 $models = json_decode( $response, true ); 63 // Verification if the OpenAI API is down. 64 if ( isset( $models['error'] ) ) { 65 $bad_gateway = strpos( strtolower( $models['error']['message'] ), 'bad gateway' ); 66 if ( $bad_gateway !== false ) { 67 return true; 68 } 69 } 70 } catch ( \Exception $e ) { 71 // Log error but don't crash the page 72 if ( WDGPT_DEBUG_MODE ) { 73 WDGPT_Error_Logs::wdgpt_log_error( 'Error checking API status: ' . $e->getMessage(), 500, 'wdgpt_is_api_down' ); 74 } 75 return false; 61 76 } 62 77 return false; … … 77 92 WDGPT_Error_Logs::wdgpt_log_error( 'Active posts : '.count($active_posts) .' (Must be greater than 0)', 200, 'wdgpt_should_display'); 78 93 WDGPT_Error_Logs::wdgpt_log_error( 'Pending update : '.$has_pending_database_update, 200, 'wdgpt_should_display'); 79 WDGPT_Error_Logs::wdgpt_log_error( 'OPENAI API down : ' . ( wdgpt_is_api_down() ? 'YES' : 'NO' ), 200, 'wdgpt_should_display' ); 94 try { 95 $api_down = wdgpt_is_api_down(); 96 WDGPT_Error_Logs::wdgpt_log_error( 'OPENAI API down : ' . ( $api_down ? 'YES' : 'NO' ), 200, 'wdgpt_should_display' ); 97 } catch ( \Exception $e ) { 98 WDGPT_Error_Logs::wdgpt_log_error( 'Error checking API status in should_display: ' . $e->getMessage(), 500, 'wdgpt_should_display' ); 99 } 80 100 WDGPT_Error_Logs::wdgpt_log_error('allow_url_fopen enabled: ' . (ini_get('allow_url_fopen') ? 'YES' : 'NO'), 200, 'wdgpt_debug'); 81 101 } 102 103 // Safely check API status - if it fails, assume API is not down 104 $is_api_down = false; 105 try { 106 $is_api_down = wdgpt_is_api_down(); 107 } catch ( \Exception $e ) { 108 // If checking API status fails, don't block the chatbot 109 if ( WDGPT_DEBUG_MODE ) { 110 WDGPT_Error_Logs::wdgpt_log_error( 'Error in wdgpt_is_api_down: ' . $e->getMessage(), 500, 'wdgpt_should_display' ); 111 } 112 } 113 82 114 return 'on' === $enable_bot && 83 115 count( $active_posts ) > 0 && 84 116 wdgpt_is_api_key_set() && 85 117 ! $has_pending_database_update && 86 ! wdgpt_is_api_down()&&118 ! $is_api_down && 87 119 ini_get( 'allow_url_fopen' ); 88 120 } -
smartsearchwp/trunk/includes/wdgpt-config.php
r3308046 r3389096 123 123 return array(); 124 124 } 125 $openai_client = new OpenAI( $openai_api_key ); 126 $models = json_decode( $openai_client->listModels(), true ); 127 if ( isset( $models['error'] ) || ! isset( $models['data'] ) ) { 125 try { 126 $openai_client = new OpenAI( $openai_api_key ); 127 $response = $openai_client->listModels(); 128 if ( $response === false ) { 129 return array(); 130 } 131 $models = json_decode( $response, true ); 132 if ( isset( $models['error'] ) || ! isset( $models['data'] ) ) { 133 return array(); 134 } 135 } catch ( \Exception $e ) { 136 // Log error but don't crash the admin page 137 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 138 error_log( 'SmartSearchWP: Error getting models - ' . $e->getMessage() ); 139 } 128 140 return array(); 129 141 } -
smartsearchwp/trunk/readme.txt
r3362606 r3389096 4 4 Tags: chatbot, chatgpt, openai, conversational chat, customer support 5 5 Requires at least: 4.7 6 Tested up to: 6.8. 17 Stable tag: 2. 5.66 Tested up to: 6.8.3 7 Stable tag: 2.6.0 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 95 95 96 96 == Changelog == 97 98 = 2.6.0 = 99 * Add "Purge Transients" button in general settings to clear addons cache 100 * Improve error handling in API calls with try-catch blocks 101 * Enhanced stability when OpenAI API calls fail 97 102 98 103 = 2.5.6 = -
smartsearchwp/trunk/wdgpt.php
r3362606 r3389096 4 4 * Description: A chatbot that helps users navigate your website and find what they're looking for. 5 5 * Plugin URI: https://www.smartsearchwp.com/ 6 * Version: 2. 5.66 * Version: 2.6.0 7 7 * Author: Webdigit 8 8 * Author URI: https://www.smartsearchwp.com/ … … 19 19 } 20 20 21 define( 'WDGPT_CHATBOT_VERSION', '2. 5.6' );21 define( 'WDGPT_CHATBOT_VERSION', '2.6.0' ); 22 22 23 23 // Définition de la constante globale pour le mode debug
Note: See TracChangeset
for help on using the changeset viewer.