Changeset 3373032
- Timestamp:
- 10/05/2025 06:39:37 AM (6 months ago)
- Location:
- muchat-ai
- Files:
-
- 10 edited
- 1 copied
-
tags/2.0.47 (copied) (copied from muchat-ai/trunk)
-
tags/2.0.47/includes/Admin/Settings.php (modified) (2 diffs)
-
tags/2.0.47/includes/Frontend/Widget.php (modified) (2 diffs)
-
tags/2.0.47/muchat-ai.php (modified) (2 diffs)
-
tags/2.0.47/readme.txt (modified) (2 diffs)
-
tags/2.0.47/templates/admin/widget-settings.php (modified) (1 diff)
-
trunk/includes/Admin/Settings.php (modified) (2 diffs)
-
trunk/includes/Frontend/Widget.php (modified) (2 diffs)
-
trunk/muchat-ai.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/templates/admin/widget-settings.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
muchat-ai/tags/2.0.47/includes/Admin/Settings.php
r3332960 r3373032 247 247 $guest_context = get_option('muchat_ai_chatbot_guest_context', ''); 248 248 $load_strategy = get_option('muchat_ai_chatbot_load_strategy', 'FAST'); 249 $script_position = get_option('muchat_ai_chatbot_script_position', ' head');249 $script_position = get_option('muchat_ai_chatbot_script_position', 'footer'); 250 250 $use_logged_in_user_info = get_option('muchat_ai_chatbot_use_logged_in_user_info', ''); 251 251 $widget_enabled = get_option('muchat_ai_chatbot_widget_enabled', '1'); … … 838 838 register_setting('muchat-settings-group', 'muchat_ai_chatbot_script_position', array( 839 839 'type' => 'string', 840 'sanitize_callback' => 'sanitize_text_field' 840 'sanitize_callback' => function($input) { 841 $valid_positions = ['head', 'footer', 'body_open']; 842 return in_array($input, $valid_positions, true) ? $input : 'footer'; 843 }, 844 'default' => 'footer' 841 845 )); 842 846 register_setting('muchat-settings-group', 'muchat_ai_chatbot_use_logged_in_user_info', array( -
muchat-ai/tags/2.0.47/includes/Frontend/Widget.php
r3332960 r3373032 6 6 { 7 7 /** 8 * Script position setting 9 * 10 * @var string 11 */ 12 private $script_position; 13 14 /** 15 * WordPress hook used for script injection 16 * 17 * @var string 18 */ 19 private $script_hook; 20 21 /** 22 * Priority for the hook 23 * 24 * @var int 25 */ 26 private $script_priority; 27 28 /** 8 29 * Initialize the class 9 30 */ 10 31 public function __construct() 11 32 { 12 // For existing users, the option won't exist, so we default to 'head' for 13 // backward compatibility. For new installs, the default is set to 'footer' 14 // in 'includes/Admin/Settings.php' during activation. 15 $position = get_option('muchat_ai_chatbot_script_position', 'head'); 16 $hook = 'wp_head'; // Default hook 17 18 if ($position === 'footer') { 33 // Get script position setting with 'footer' as default for better performance 34 $position = get_option('muchat_ai_chatbot_script_position', 'footer'); 35 36 // Validate the position value 37 $valid_positions = ['head', 'footer', 'body_open']; 38 if (!in_array($position, $valid_positions, true)) { 39 $position = 'footer'; 40 } 41 42 $hook = 'wp_footer'; // Default hook 43 $priority = 100; // Default priority - load after most scripts 44 45 if ($position === 'head') { 46 $hook = 'wp_head'; 47 $priority = 100; // Still use late priority for better compatibility 48 } elseif ($position === 'footer') { 19 49 $hook = 'wp_footer'; 50 $priority = 100; // Load after most footer scripts 20 51 } elseif ($position === 'body_open') { 21 52 // wp_body_open was introduced in WP 5.2. 22 // We'll use it if available, otherwise fallback to wp_footer. 23 if (function_exists('wp_body_open')) { 24 $hook = 'wp_body_open'; 25 } else { 26 $hook = 'wp_footer'; 27 } 28 } 29 30 add_action($hook, [$this, 'hook_head'], 1); 53 $hook = 'wp_body_open'; 54 $priority = 20; // Use earlier priority for body_open 55 } 56 57 add_action($hook, [$this, 'render_widget'], $priority); 31 58 $this->register_cache_clearing_hooks(); 59 60 // Store for potential debugging 61 $this->script_position = $position; 62 $this->script_hook = $hook; 63 $this->script_priority = $priority; 32 64 } 33 65 … … 54 86 55 87 /** 56 * Hook into wp_head to inject widget 57 */ 58 public function hook_head() 59 { 88 * Render the widget on the frontend 89 */ 90 public function render_widget() 91 { 92 // Add debug comment for admins 93 if (current_user_can('manage_options')) { 94 echo "\n<!-- Muchat Widget | Position: " . esc_html($this->script_position ?? 'unknown') . 95 " | Hook: " . esc_html($this->script_hook ?? 'unknown') . 96 " | Priority: " . esc_html($this->script_priority ?? 'unknown') . " -->\n"; 97 } 98 60 99 // Check for agent ID 61 100 $agent_id = get_option('muchat_ai_chatbot_agent_id'); -
muchat-ai/tags/2.0.47/muchat-ai.php
r3372770 r3373032 5 5 * Plugin URI: https://mu.chat 6 6 * Description: Muchat, a powerful tool for customer support using artificial intelligence 7 * Version: 2.0.4 67 * Version: 2.0.47 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.4 6');29 define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.47'); 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.47/readme.txt
r3372770 r3373032 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 2.0.4 66 Stable tag: 2.0.47 7 7 Requires PHP: 7.3 8 8 License: GPLv2 or later … … 75 75 76 76 == Changelog == 77 78 = 2.0.47 = 79 * Fix: Improved Script Load Position implementation with proper priority handling for better mobile compatibility. 80 * Fix: Resolved critical issue where scripts were loading too early (priority 1) causing conflicts and mobile display issues. 81 * Fix: Corrected default value inconsistency - now consistently defaults to 'footer' for optimal performance. 82 * Tweak: Added validation for script position values to prevent invalid configurations. 83 * Feature: Added debug HTML comment for administrators to verify script load position (visible in page source). 84 * Tweak: Enhanced admin UI with clearer descriptions for each Script Load Position option. 85 * Tweak: Removed misleading theme support warning that appeared even when themes properly supported the feature. 77 86 78 87 = 2.0.46 = -
muchat-ai/tags/2.0.47/templates/admin/widget-settings.php
r3332960 r3373032 189 189 <th scope="row"><?php esc_html_e('Script Load Position', 'muchat-ai'); ?></th> 190 190 <td> 191 <select name="muchat_ai_chatbot_script_position" class="regular-text" >192 <option value="footer" <?php selected($script_position, 'footer'); ?>><?php esc_html_e('Footer (Recommended for Performance)', 'muchat-ai'); ?></option>191 <select name="muchat_ai_chatbot_script_position" class="regular-text" id="muchat_ai_chatbot_script_position"> 192 <option value="footer" <?php selected($script_position, 'footer'); ?>><?php esc_html_e('Footer (Recommended)', 'muchat-ai'); ?></option> 193 193 <option value="head" <?php selected($script_position, 'head'); ?>><?php esc_html_e('Header', 'muchat-ai'); ?></option> 194 194 <option value="body_open" <?php selected($script_position, 'body_open'); ?>><?php esc_html_e('Body Opening', 'muchat-ai'); ?></option> 195 195 </select> 196 196 <p class="description"> 197 <?php esc_html_e('Determines where the widget script is loaded on your page. Loading in the footer improves page speed.', 'muchat-ai'); ?> 197 <strong><?php esc_html_e('Footer (Recommended):', 'muchat-ai'); ?></strong> <?php esc_html_e('Best for page speed and mobile compatibility. Loads after the page content.', 'muchat-ai'); ?><br> 198 <strong><?php esc_html_e('Header:', 'muchat-ai'); ?></strong> <?php esc_html_e('Loads in the <head> section. Use if you need the widget available as early as possible.', 'muchat-ai'); ?><br> 199 <strong><?php esc_html_e('Body Opening:', 'muchat-ai'); ?></strong> <?php esc_html_e('Loads right after <body> tag. Requires WordPress 5.2+ and modern theme support.', 'muchat-ai'); ?> 198 200 </p> 199 201 </td> -
muchat-ai/trunk/includes/Admin/Settings.php
r3332960 r3373032 247 247 $guest_context = get_option('muchat_ai_chatbot_guest_context', ''); 248 248 $load_strategy = get_option('muchat_ai_chatbot_load_strategy', 'FAST'); 249 $script_position = get_option('muchat_ai_chatbot_script_position', ' head');249 $script_position = get_option('muchat_ai_chatbot_script_position', 'footer'); 250 250 $use_logged_in_user_info = get_option('muchat_ai_chatbot_use_logged_in_user_info', ''); 251 251 $widget_enabled = get_option('muchat_ai_chatbot_widget_enabled', '1'); … … 838 838 register_setting('muchat-settings-group', 'muchat_ai_chatbot_script_position', array( 839 839 'type' => 'string', 840 'sanitize_callback' => 'sanitize_text_field' 840 'sanitize_callback' => function($input) { 841 $valid_positions = ['head', 'footer', 'body_open']; 842 return in_array($input, $valid_positions, true) ? $input : 'footer'; 843 }, 844 'default' => 'footer' 841 845 )); 842 846 register_setting('muchat-settings-group', 'muchat_ai_chatbot_use_logged_in_user_info', array( -
muchat-ai/trunk/includes/Frontend/Widget.php
r3332960 r3373032 6 6 { 7 7 /** 8 * Script position setting 9 * 10 * @var string 11 */ 12 private $script_position; 13 14 /** 15 * WordPress hook used for script injection 16 * 17 * @var string 18 */ 19 private $script_hook; 20 21 /** 22 * Priority for the hook 23 * 24 * @var int 25 */ 26 private $script_priority; 27 28 /** 8 29 * Initialize the class 9 30 */ 10 31 public function __construct() 11 32 { 12 // For existing users, the option won't exist, so we default to 'head' for 13 // backward compatibility. For new installs, the default is set to 'footer' 14 // in 'includes/Admin/Settings.php' during activation. 15 $position = get_option('muchat_ai_chatbot_script_position', 'head'); 16 $hook = 'wp_head'; // Default hook 17 18 if ($position === 'footer') { 33 // Get script position setting with 'footer' as default for better performance 34 $position = get_option('muchat_ai_chatbot_script_position', 'footer'); 35 36 // Validate the position value 37 $valid_positions = ['head', 'footer', 'body_open']; 38 if (!in_array($position, $valid_positions, true)) { 39 $position = 'footer'; 40 } 41 42 $hook = 'wp_footer'; // Default hook 43 $priority = 100; // Default priority - load after most scripts 44 45 if ($position === 'head') { 46 $hook = 'wp_head'; 47 $priority = 100; // Still use late priority for better compatibility 48 } elseif ($position === 'footer') { 19 49 $hook = 'wp_footer'; 50 $priority = 100; // Load after most footer scripts 20 51 } elseif ($position === 'body_open') { 21 52 // wp_body_open was introduced in WP 5.2. 22 // We'll use it if available, otherwise fallback to wp_footer. 23 if (function_exists('wp_body_open')) { 24 $hook = 'wp_body_open'; 25 } else { 26 $hook = 'wp_footer'; 27 } 28 } 29 30 add_action($hook, [$this, 'hook_head'], 1); 53 $hook = 'wp_body_open'; 54 $priority = 20; // Use earlier priority for body_open 55 } 56 57 add_action($hook, [$this, 'render_widget'], $priority); 31 58 $this->register_cache_clearing_hooks(); 59 60 // Store for potential debugging 61 $this->script_position = $position; 62 $this->script_hook = $hook; 63 $this->script_priority = $priority; 32 64 } 33 65 … … 54 86 55 87 /** 56 * Hook into wp_head to inject widget 57 */ 58 public function hook_head() 59 { 88 * Render the widget on the frontend 89 */ 90 public function render_widget() 91 { 92 // Add debug comment for admins 93 if (current_user_can('manage_options')) { 94 echo "\n<!-- Muchat Widget | Position: " . esc_html($this->script_position ?? 'unknown') . 95 " | Hook: " . esc_html($this->script_hook ?? 'unknown') . 96 " | Priority: " . esc_html($this->script_priority ?? 'unknown') . " -->\n"; 97 } 98 60 99 // Check for agent ID 61 100 $agent_id = get_option('muchat_ai_chatbot_agent_id'); -
muchat-ai/trunk/muchat-ai.php
r3372770 r3373032 5 5 * Plugin URI: https://mu.chat 6 6 * Description: Muchat, a powerful tool for customer support using artificial intelligence 7 * Version: 2.0.4 67 * Version: 2.0.47 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.4 6');29 define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.47'); 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
r3372770 r3373032 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 2.0.4 66 Stable tag: 2.0.47 7 7 Requires PHP: 7.3 8 8 License: GPLv2 or later … … 75 75 76 76 == Changelog == 77 78 = 2.0.47 = 79 * Fix: Improved Script Load Position implementation with proper priority handling for better mobile compatibility. 80 * Fix: Resolved critical issue where scripts were loading too early (priority 1) causing conflicts and mobile display issues. 81 * Fix: Corrected default value inconsistency - now consistently defaults to 'footer' for optimal performance. 82 * Tweak: Added validation for script position values to prevent invalid configurations. 83 * Feature: Added debug HTML comment for administrators to verify script load position (visible in page source). 84 * Tweak: Enhanced admin UI with clearer descriptions for each Script Load Position option. 85 * Tweak: Removed misleading theme support warning that appeared even when themes properly supported the feature. 77 86 78 87 = 2.0.46 = -
muchat-ai/trunk/templates/admin/widget-settings.php
r3332960 r3373032 189 189 <th scope="row"><?php esc_html_e('Script Load Position', 'muchat-ai'); ?></th> 190 190 <td> 191 <select name="muchat_ai_chatbot_script_position" class="regular-text" >192 <option value="footer" <?php selected($script_position, 'footer'); ?>><?php esc_html_e('Footer (Recommended for Performance)', 'muchat-ai'); ?></option>191 <select name="muchat_ai_chatbot_script_position" class="regular-text" id="muchat_ai_chatbot_script_position"> 192 <option value="footer" <?php selected($script_position, 'footer'); ?>><?php esc_html_e('Footer (Recommended)', 'muchat-ai'); ?></option> 193 193 <option value="head" <?php selected($script_position, 'head'); ?>><?php esc_html_e('Header', 'muchat-ai'); ?></option> 194 194 <option value="body_open" <?php selected($script_position, 'body_open'); ?>><?php esc_html_e('Body Opening', 'muchat-ai'); ?></option> 195 195 </select> 196 196 <p class="description"> 197 <?php esc_html_e('Determines where the widget script is loaded on your page. Loading in the footer improves page speed.', 'muchat-ai'); ?> 197 <strong><?php esc_html_e('Footer (Recommended):', 'muchat-ai'); ?></strong> <?php esc_html_e('Best for page speed and mobile compatibility. Loads after the page content.', 'muchat-ai'); ?><br> 198 <strong><?php esc_html_e('Header:', 'muchat-ai'); ?></strong> <?php esc_html_e('Loads in the <head> section. Use if you need the widget available as early as possible.', 'muchat-ai'); ?><br> 199 <strong><?php esc_html_e('Body Opening:', 'muchat-ai'); ?></strong> <?php esc_html_e('Loads right after <body> tag. Requires WordPress 5.2+ and modern theme support.', 'muchat-ai'); ?> 198 200 </p> 199 201 </td>
Note: See TracChangeset
for help on using the changeset viewer.