Plugin Directory

Changeset 3330925


Ignore:
Timestamp:
07/20/2025 01:05:04 PM (9 months ago)
Author:
muchatai
Message:

Update to version 2.0.39 from GitHub

Location:
muchat-ai
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • muchat-ai/tags/2.0.39/includes/Admin/Settings.php

    r3330738 r3330925  
    296296        // Include the template
    297297        require_once MUCHAT_AI_CHATBOT_PLUGIN_PATH . 'templates/admin/widget-settings.php';
     298    }
     299
     300    /**
     301     * Checks the connection status to Muchat servers.
     302     *
     303     * Performs a lightweight HEAD request to check for connectivity. The result is
     304     * cached for 5 minutes in a transient to avoid excessive requests on page load.
     305     *
     306     * @return array An array containing 'success' (bool) and 'message' (string).
     307     */
     308    public function check_muchat_connection_status()
     309    {
     310        $transient_key = 'muchat_connection_status';
     311
     312        // Return cached status if available.
     313        $cached_status = get_transient($transient_key);
     314        if (false !== $cached_status) {
     315            return $cached_status;
     316        }
     317
     318        // Get server IP for debugging purposes.
     319        $server_ip = isset($_SERVER['SERVER_ADDR']) ? sanitize_text_field($_SERVER['SERVER_ADDR']) : 'IP not detectable';
     320
     321        // Default status assumes failure.
     322        $status = [
     323            'success' => false,
     324            'message' => __('Could not establish a connection to Muchat servers.', 'muchat-ai'),
     325        ];
     326
     327        $response = wp_remote_head('https://app.mu.chat', ['timeout' => 10]);
     328
     329        if (is_wp_error($response)) {
     330            // WordPress-level error (e.g., cURL error, DNS issue).
     331            $status['message'] = sprintf(
     332                // translators: 1: The server IP address, 2: The specific error message from WordPress.
     333                __('Your server (IP: %1$s) cannot connect to Muchat. Error: %2$s', 'muchat-ai'),
     334                $server_ip,
     335                $response->get_error_message()
     336            );
     337        } else {
     338            // We have a response, check the HTTP status code.
     339            $response_code = wp_remote_retrieve_response_code($response);
     340
     341            if ($response_code >= 200 && $response_code < 400) {
     342                // Success (2xx) or Redirect (3xx) are considered successful connections.
     343                $status = [
     344                    'success' => true,
     345                    'message' => sprintf(
     346                        // translators: %s: The server IP address.
     347                        __('Connection from your server (IP: %s) to Muchat is successful.', 'muchat-ai'),
     348                        $server_ip
     349                    ),
     350                ];
     351            } else {
     352                // Server responded with an error code (4xx, 5xx).
     353                $status['message'] = sprintf(
     354                    // translators: 1: The server IP address, 2: The HTTP status code from the server.
     355                    __('Your server (IP: %1$s) connected to Muchat, but received an error. Status code: %2$d', 'muchat-ai'),
     356                    $server_ip,
     357                    $response_code
     358                );
     359            }
     360        }
     361
     362        // Cache the result for 5 minutes.
     363        set_transient($transient_key, $status, 5 * MINUTE_IN_SECONDS);
     364
     365        return $status;
    298366    }
    299367
     
    546614    public function register_settings()
    547615    {
     616        // Handle cache clearing for connection status check
     617        if (
     618            isset($_GET['action']) &&
     619            $_GET['action'] === 'muchat_check_connection' &&
     620            isset($_GET['_wpnonce']) &&
     621            wp_verify_nonce(sanitize_key($_GET['_wpnonce']), 'muchat_check_connection_action')
     622        ) {
     623            delete_transient('muchat_connection_status');
     624            add_settings_error(
     625                'muchat_ai_chatbot_plugin_messages',
     626                'connection_rechecked',
     627                __('Connection status has been re-checked.', 'muchat-ai'),
     628                'info'
     629            );
     630        }
     631
    548632        // Handle cache clearing action
    549633        if (
     
    647731            return;
    648732        }
     733
     734        // Get connection status
     735        $connection_status = $this->check_muchat_connection_status();
    649736
    650737        $options = get_option('muchat_ai_chatbot_plugin_options', []);
  • muchat-ai/tags/2.0.39/muchat-ai.php

    r3330738 r3330925  
    55 * Plugin URI: https://mu.chat
    66 * Description: Muchat, a powerful tool for customer support using artificial intelligence
    7  * Version: 2.0.38
     7 * Version: 2.0.39
    88 * Author: Muchat
    99 * Text Domain: muchat-ai
     
    2727
    2828// Define plugin constants with unique prefix
    29 define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.38');
     29define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.39');
    3030// define('MUCHAT_AI_CHATBOT_CACHE_DURATION', HOUR_IN_SECONDS);
    3131define('MUCHAT_AI_CHATBOT_PLUGIN_FILE', __FILE__);
  • muchat-ai/tags/2.0.39/readme.txt

    r3330738 r3330925  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 2.0.38
     6Stable tag: 2.0.39
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    7676== Changelog ==
    7777
     78= 2.0.39 =
     79* Feature: Added check app status
     80
    7881= 2.0.38 =
    7982- Feature: Added an option for different initial messages for guest (non-logged-in) users.
  • muchat-ai/tags/2.0.39/templates/admin/settings.php

    r3330738 r3330925  
    1414
    1515    <hr class="wp-header-end">
     16
     17    <!-- Connection Status Indicator -->
     18    <div class="notice" style="border-left-color: <?php echo $connection_status['success'] ? '#4CAF50' : '#F44336'; ?>; display: flex; align-items: center; justify-content: space-between; padding: 10px 15px;">
     19        <div style="display: flex; align-items: center;">
     20            <span class="dashicons <?php echo $connection_status['success'] ? 'dashicons-yes-alt' : 'dashicons-warning'; ?>" style="font-size: 24px; margin-right: 10px; color: <?php echo $connection_status['success'] ? '#4CAF50' : '#F44336'; ?>;"></span>
     21            <div>
     22                <strong><?php esc_html_e('Muchat Server Connection', 'muchat-ai'); ?></strong><br>
     23                <small><?php echo esc_html($connection_status['message']); ?></small>
     24            </div>
     25        </div>
     26        <form method="get">
     27            <input type="hidden" name="page" value="muchat-woocommerce-api">
     28            <input type="hidden" name="action" value="muchat_check_connection">
     29            <?php wp_nonce_field('muchat_check_connection_action'); ?>
     30            <button type="submit" class="button button-secondary">
     31                <span class="dashicons dashicons-update" style="vertical-align: text-top; margin-right: 3px;"></span>
     32                <?php esc_html_e('Re-check', 'muchat-ai'); ?>
     33            </button>
     34        </form>
     35    </div>
     36
    1637
    1738    <?php settings_errors('muchat_ai_chatbot_plugin_messages'); ?>
  • muchat-ai/trunk/includes/Admin/Settings.php

    r3330738 r3330925  
    296296        // Include the template
    297297        require_once MUCHAT_AI_CHATBOT_PLUGIN_PATH . 'templates/admin/widget-settings.php';
     298    }
     299
     300    /**
     301     * Checks the connection status to Muchat servers.
     302     *
     303     * Performs a lightweight HEAD request to check for connectivity. The result is
     304     * cached for 5 minutes in a transient to avoid excessive requests on page load.
     305     *
     306     * @return array An array containing 'success' (bool) and 'message' (string).
     307     */
     308    public function check_muchat_connection_status()
     309    {
     310        $transient_key = 'muchat_connection_status';
     311
     312        // Return cached status if available.
     313        $cached_status = get_transient($transient_key);
     314        if (false !== $cached_status) {
     315            return $cached_status;
     316        }
     317
     318        // Get server IP for debugging purposes.
     319        $server_ip = isset($_SERVER['SERVER_ADDR']) ? sanitize_text_field($_SERVER['SERVER_ADDR']) : 'IP not detectable';
     320
     321        // Default status assumes failure.
     322        $status = [
     323            'success' => false,
     324            'message' => __('Could not establish a connection to Muchat servers.', 'muchat-ai'),
     325        ];
     326
     327        $response = wp_remote_head('https://app.mu.chat', ['timeout' => 10]);
     328
     329        if (is_wp_error($response)) {
     330            // WordPress-level error (e.g., cURL error, DNS issue).
     331            $status['message'] = sprintf(
     332                // translators: 1: The server IP address, 2: The specific error message from WordPress.
     333                __('Your server (IP: %1$s) cannot connect to Muchat. Error: %2$s', 'muchat-ai'),
     334                $server_ip,
     335                $response->get_error_message()
     336            );
     337        } else {
     338            // We have a response, check the HTTP status code.
     339            $response_code = wp_remote_retrieve_response_code($response);
     340
     341            if ($response_code >= 200 && $response_code < 400) {
     342                // Success (2xx) or Redirect (3xx) are considered successful connections.
     343                $status = [
     344                    'success' => true,
     345                    'message' => sprintf(
     346                        // translators: %s: The server IP address.
     347                        __('Connection from your server (IP: %s) to Muchat is successful.', 'muchat-ai'),
     348                        $server_ip
     349                    ),
     350                ];
     351            } else {
     352                // Server responded with an error code (4xx, 5xx).
     353                $status['message'] = sprintf(
     354                    // translators: 1: The server IP address, 2: The HTTP status code from the server.
     355                    __('Your server (IP: %1$s) connected to Muchat, but received an error. Status code: %2$d', 'muchat-ai'),
     356                    $server_ip,
     357                    $response_code
     358                );
     359            }
     360        }
     361
     362        // Cache the result for 5 minutes.
     363        set_transient($transient_key, $status, 5 * MINUTE_IN_SECONDS);
     364
     365        return $status;
    298366    }
    299367
     
    546614    public function register_settings()
    547615    {
     616        // Handle cache clearing for connection status check
     617        if (
     618            isset($_GET['action']) &&
     619            $_GET['action'] === 'muchat_check_connection' &&
     620            isset($_GET['_wpnonce']) &&
     621            wp_verify_nonce(sanitize_key($_GET['_wpnonce']), 'muchat_check_connection_action')
     622        ) {
     623            delete_transient('muchat_connection_status');
     624            add_settings_error(
     625                'muchat_ai_chatbot_plugin_messages',
     626                'connection_rechecked',
     627                __('Connection status has been re-checked.', 'muchat-ai'),
     628                'info'
     629            );
     630        }
     631
    548632        // Handle cache clearing action
    549633        if (
     
    647731            return;
    648732        }
     733
     734        // Get connection status
     735        $connection_status = $this->check_muchat_connection_status();
    649736
    650737        $options = get_option('muchat_ai_chatbot_plugin_options', []);
  • muchat-ai/trunk/muchat-ai.php

    r3330738 r3330925  
    55 * Plugin URI: https://mu.chat
    66 * Description: Muchat, a powerful tool for customer support using artificial intelligence
    7  * Version: 2.0.38
     7 * Version: 2.0.39
    88 * Author: Muchat
    99 * Text Domain: muchat-ai
     
    2727
    2828// Define plugin constants with unique prefix
    29 define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.38');
     29define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.39');
    3030// define('MUCHAT_AI_CHATBOT_CACHE_DURATION', HOUR_IN_SECONDS);
    3131define('MUCHAT_AI_CHATBOT_PLUGIN_FILE', __FILE__);
  • muchat-ai/trunk/readme.txt

    r3330738 r3330925  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 2.0.38
     6Stable tag: 2.0.39
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    7676== Changelog ==
    7777
     78= 2.0.39 =
     79* Feature: Added check app status
     80
    7881= 2.0.38 =
    7982- Feature: Added an option for different initial messages for guest (non-logged-in) users.
  • muchat-ai/trunk/templates/admin/settings.php

    r3330738 r3330925  
    1414
    1515    <hr class="wp-header-end">
     16
     17    <!-- Connection Status Indicator -->
     18    <div class="notice" style="border-left-color: <?php echo $connection_status['success'] ? '#4CAF50' : '#F44336'; ?>; display: flex; align-items: center; justify-content: space-between; padding: 10px 15px;">
     19        <div style="display: flex; align-items: center;">
     20            <span class="dashicons <?php echo $connection_status['success'] ? 'dashicons-yes-alt' : 'dashicons-warning'; ?>" style="font-size: 24px; margin-right: 10px; color: <?php echo $connection_status['success'] ? '#4CAF50' : '#F44336'; ?>;"></span>
     21            <div>
     22                <strong><?php esc_html_e('Muchat Server Connection', 'muchat-ai'); ?></strong><br>
     23                <small><?php echo esc_html($connection_status['message']); ?></small>
     24            </div>
     25        </div>
     26        <form method="get">
     27            <input type="hidden" name="page" value="muchat-woocommerce-api">
     28            <input type="hidden" name="action" value="muchat_check_connection">
     29            <?php wp_nonce_field('muchat_check_connection_action'); ?>
     30            <button type="submit" class="button button-secondary">
     31                <span class="dashicons dashicons-update" style="vertical-align: text-top; margin-right: 3px;"></span>
     32                <?php esc_html_e('Re-check', 'muchat-ai'); ?>
     33            </button>
     34        </form>
     35    </div>
     36
    1637
    1738    <?php settings_errors('muchat_ai_chatbot_plugin_messages'); ?>
Note: See TracChangeset for help on using the changeset viewer.