Plugin Directory

Changeset 3389096


Ignore:
Timestamp:
11/03/2025 07:00:40 PM (5 months ago)
Author:
webdigit
Message:

Version 2.6.0 : ajout de la gestion avancée des logs, amélioration de la stabilité, compatibilité WP 6.8.3

Location:
smartsearchwp/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • smartsearchwp/trunk/includes/config/wdgpt-config-general-settings.php

    r3241701 r3389096  
    119119        wdgpt_general_settings_save_options();
    120120    }
     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    }
    121129    ?>
    122130        <?php wp_nonce_field( 'wdgpt_settings', 'wdgpt_settings_nonce' ); ?>
     
    237245                </select>
    238246                <?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                    }
    240257                    $selected_model        = get_option( 'wdgpt_model', '' );
    241258                    $selected_model_exists = false;
    242259                foreach ( $available_models as $model ) {
    243                     if ( $model['id'] === $selected_model ) {
     260                    if ( isset( $model['id'] ) && $model['id'] === $selected_model ) {
    244261                        $selected_model_exists = true;
    245262                        break;
     
    529546            </td>
    530547        </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>
    531566        </table>
    532567        <input type='submit' name='submit' value='
     
    563598}
    564599
     600/**
     601 * Purge transients cache.
     602 *
     603 * @return void
     604 */
     605function 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
    565613
    566614?>
  • smartsearchwp/trunk/includes/wdgpt-client.php

    r3308372 r3389096  
    5050 */
    5151function 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;
    6176    }
    6277    return false;
     
    7792        WDGPT_Error_Logs::wdgpt_log_error( 'Active posts : '.count($active_posts) .' (Must be greater than 0)', 200, 'wdgpt_should_display');
    7893        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        }
    80100        WDGPT_Error_Logs::wdgpt_log_error('allow_url_fopen enabled: ' . (ini_get('allow_url_fopen') ? 'YES' : 'NO'), 200, 'wdgpt_debug');
    81101    }
     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   
    82114    return 'on' === $enable_bot &&
    83115            count( $active_posts ) > 0 &&
    84116            wdgpt_is_api_key_set() &&
    85117            ! $has_pending_database_update &&
    86             ! wdgpt_is_api_down() &&
     118            ! $is_api_down &&
    87119            ini_get( 'allow_url_fopen' );
    88120}
  • smartsearchwp/trunk/includes/wdgpt-config.php

    r3308046 r3389096  
    123123        return array();
    124124    }
    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        }
    128140        return array();
    129141    }
  • smartsearchwp/trunk/readme.txt

    r3362606 r3389096  
    44Tags: chatbot, chatgpt, openai, conversational chat, customer support
    55Requires at least: 4.7
    6 Tested up to: 6.8.1
    7 Stable tag: 2.5.6
     6Tested up to: 6.8.3
     7Stable tag: 2.6.0
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    9595
    9696== 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
    97102
    98103= 2.5.6 =
  • smartsearchwp/trunk/wdgpt.php

    r3362606 r3389096  
    44 * Description: A chatbot that helps users navigate your website and find what they're looking for.
    55 * Plugin URI:  https://www.smartsearchwp.com/
    6  * Version:     2.5.6
     6 * Version:     2.6.0
    77 * Author:      Webdigit
    88 * Author URI:  https://www.smartsearchwp.com/
     
    1919}
    2020
    21 define( 'WDGPT_CHATBOT_VERSION', '2.5.6' );
     21define( 'WDGPT_CHATBOT_VERSION', '2.6.0' );
    2222
    2323// Définition de la constante globale pour le mode debug
Note: See TracChangeset for help on using the changeset viewer.