Changeset 3330925
- Timestamp:
- 07/20/2025 01:05:04 PM (9 months ago)
- Location:
- muchat-ai
- Files:
-
- 8 edited
- 1 copied
-
tags/2.0.39 (copied) (copied from muchat-ai/trunk)
-
tags/2.0.39/includes/Admin/Settings.php (modified) (3 diffs)
-
tags/2.0.39/muchat-ai.php (modified) (2 diffs)
-
tags/2.0.39/readme.txt (modified) (2 diffs)
-
tags/2.0.39/templates/admin/settings.php (modified) (1 diff)
-
trunk/includes/Admin/Settings.php (modified) (3 diffs)
-
trunk/muchat-ai.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/templates/admin/settings.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
muchat-ai/tags/2.0.39/includes/Admin/Settings.php
r3330738 r3330925 296 296 // Include the template 297 297 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; 298 366 } 299 367 … … 546 614 public function register_settings() 547 615 { 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 548 632 // Handle cache clearing action 549 633 if ( … … 647 731 return; 648 732 } 733 734 // Get connection status 735 $connection_status = $this->check_muchat_connection_status(); 649 736 650 737 $options = get_option('muchat_ai_chatbot_plugin_options', []); -
muchat-ai/tags/2.0.39/muchat-ai.php
r3330738 r3330925 5 5 * Plugin URI: https://mu.chat 6 6 * Description: Muchat, a powerful tool for customer support using artificial intelligence 7 * Version: 2.0.3 87 * Version: 2.0.39 8 8 * Author: Muchat 9 9 * Text Domain: muchat-ai … … 27 27 28 28 // Define plugin constants with unique prefix 29 define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.3 8');29 define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.39'); 30 30 // define('MUCHAT_AI_CHATBOT_CACHE_DURATION', HOUR_IN_SECONDS); 31 31 define('MUCHAT_AI_CHATBOT_PLUGIN_FILE', __FILE__); -
muchat-ai/tags/2.0.39/readme.txt
r3330738 r3330925 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 2.0.3 86 Stable tag: 2.0.39 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later … … 76 76 == Changelog == 77 77 78 = 2.0.39 = 79 * Feature: Added check app status 80 78 81 = 2.0.38 = 79 82 - 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 14 14 15 15 <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 16 37 17 38 <?php settings_errors('muchat_ai_chatbot_plugin_messages'); ?> -
muchat-ai/trunk/includes/Admin/Settings.php
r3330738 r3330925 296 296 // Include the template 297 297 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; 298 366 } 299 367 … … 546 614 public function register_settings() 547 615 { 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 548 632 // Handle cache clearing action 549 633 if ( … … 647 731 return; 648 732 } 733 734 // Get connection status 735 $connection_status = $this->check_muchat_connection_status(); 649 736 650 737 $options = get_option('muchat_ai_chatbot_plugin_options', []); -
muchat-ai/trunk/muchat-ai.php
r3330738 r3330925 5 5 * Plugin URI: https://mu.chat 6 6 * Description: Muchat, a powerful tool for customer support using artificial intelligence 7 * Version: 2.0.3 87 * Version: 2.0.39 8 8 * Author: Muchat 9 9 * Text Domain: muchat-ai … … 27 27 28 28 // Define plugin constants with unique prefix 29 define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.3 8');29 define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.39'); 30 30 // define('MUCHAT_AI_CHATBOT_CACHE_DURATION', HOUR_IN_SECONDS); 31 31 define('MUCHAT_AI_CHATBOT_PLUGIN_FILE', __FILE__); -
muchat-ai/trunk/readme.txt
r3330738 r3330925 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 2.0.3 86 Stable tag: 2.0.39 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later … … 76 76 == Changelog == 77 77 78 = 2.0.39 = 79 * Feature: Added check app status 80 78 81 = 2.0.38 = 79 82 - Feature: Added an option for different initial messages for guest (non-logged-in) users. -
muchat-ai/trunk/templates/admin/settings.php
r3330738 r3330925 14 14 15 15 <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 16 37 17 38 <?php settings_errors('muchat_ai_chatbot_plugin_messages'); ?>
Note: See TracChangeset
for help on using the changeset viewer.