Plugin Directory

Changeset 3373032


Ignore:
Timestamp:
10/05/2025 06:39:37 AM (6 months ago)
Author:
muchatai
Message:

Update to version 2.0.47 from GitHub

Location:
muchat-ai
Files:
10 edited
1 copied

Legend:

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

    r3332960 r3373032  
    247247        $guest_context = get_option('muchat_ai_chatbot_guest_context', '');
    248248        $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');
    250250        $use_logged_in_user_info = get_option('muchat_ai_chatbot_use_logged_in_user_info', '');
    251251        $widget_enabled = get_option('muchat_ai_chatbot_widget_enabled', '1');
     
    838838        register_setting('muchat-settings-group', 'muchat_ai_chatbot_script_position', array(
    839839            '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'
    841845        ));
    842846        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  
    66{
    77    /**
     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    /**
    829     * Initialize the class
    930     */
    1031    public function __construct()
    1132    {
    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') {
    1949            $hook = 'wp_footer';
     50            $priority = 100; // Load after most footer scripts
    2051        } elseif ($position === 'body_open') {
    2152            // 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);
    3158        $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;
    3264    }
    3365
     
    5486
    5587    /**
    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       
    6099        // Check for agent ID
    61100        $agent_id = get_option('muchat_ai_chatbot_agent_id');
  • muchat-ai/tags/2.0.47/muchat-ai.php

    r3372770 r3373032  
    55 * Plugin URI: https://mu.chat
    66 * Description: Muchat, a powerful tool for customer support using artificial intelligence
    7  * Version: 2.0.46
     7 * Version: 2.0.47
    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.46');
     29define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.47');
    3030// define('MUCHAT_AI_CHATBOT_CACHE_DURATION', HOUR_IN_SECONDS);
    3131define('MUCHAT_AI_CHATBOT_PLUGIN_FILE', __FILE__);
  • muchat-ai/tags/2.0.47/readme.txt

    r3372770 r3373032  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 2.0.46
     6Stable tag: 2.0.47
    77Requires PHP: 7.3
    88License: GPLv2 or later
     
    7575
    7676== 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.
    7786
    7887= 2.0.46 =
  • muchat-ai/tags/2.0.47/templates/admin/widget-settings.php

    r3332960 r3373032  
    189189                                <th scope="row"><?php esc_html_e('Script Load Position', 'muchat-ai'); ?></th>
    190190                                <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>
    193193                                        <option value="head" <?php selected($script_position, 'head'); ?>><?php esc_html_e('Header', 'muchat-ai'); ?></option>
    194194                                        <option value="body_open" <?php selected($script_position, 'body_open'); ?>><?php esc_html_e('Body Opening', 'muchat-ai'); ?></option>
    195195                                    </select>
    196196                                    <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'); ?>
    198200                                    </p>
    199201                                </td>
  • muchat-ai/trunk/includes/Admin/Settings.php

    r3332960 r3373032  
    247247        $guest_context = get_option('muchat_ai_chatbot_guest_context', '');
    248248        $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');
    250250        $use_logged_in_user_info = get_option('muchat_ai_chatbot_use_logged_in_user_info', '');
    251251        $widget_enabled = get_option('muchat_ai_chatbot_widget_enabled', '1');
     
    838838        register_setting('muchat-settings-group', 'muchat_ai_chatbot_script_position', array(
    839839            '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'
    841845        ));
    842846        register_setting('muchat-settings-group', 'muchat_ai_chatbot_use_logged_in_user_info', array(
  • muchat-ai/trunk/includes/Frontend/Widget.php

    r3332960 r3373032  
    66{
    77    /**
     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    /**
    829     * Initialize the class
    930     */
    1031    public function __construct()
    1132    {
    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') {
    1949            $hook = 'wp_footer';
     50            $priority = 100; // Load after most footer scripts
    2051        } elseif ($position === 'body_open') {
    2152            // 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);
    3158        $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;
    3264    }
    3365
     
    5486
    5587    /**
    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       
    6099        // Check for agent ID
    61100        $agent_id = get_option('muchat_ai_chatbot_agent_id');
  • muchat-ai/trunk/muchat-ai.php

    r3372770 r3373032  
    55 * Plugin URI: https://mu.chat
    66 * Description: Muchat, a powerful tool for customer support using artificial intelligence
    7  * Version: 2.0.46
     7 * Version: 2.0.47
    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.46');
     29define('MUCHAT_AI_CHATBOT_PLUGIN_VERSION', '2.0.47');
    3030// define('MUCHAT_AI_CHATBOT_CACHE_DURATION', HOUR_IN_SECONDS);
    3131define('MUCHAT_AI_CHATBOT_PLUGIN_FILE', __FILE__);
  • muchat-ai/trunk/readme.txt

    r3372770 r3373032  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 2.0.46
     6Stable tag: 2.0.47
    77Requires PHP: 7.3
    88License: GPLv2 or later
     
    7575
    7676== 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.
    7786
    7887= 2.0.46 =
  • muchat-ai/trunk/templates/admin/widget-settings.php

    r3332960 r3373032  
    189189                                <th scope="row"><?php esc_html_e('Script Load Position', 'muchat-ai'); ?></th>
    190190                                <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>
    193193                                        <option value="head" <?php selected($script_position, 'head'); ?>><?php esc_html_e('Header', 'muchat-ai'); ?></option>
    194194                                        <option value="body_open" <?php selected($script_position, 'body_open'); ?>><?php esc_html_e('Body Opening', 'muchat-ai'); ?></option>
    195195                                    </select>
    196196                                    <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'); ?>
    198200                                    </p>
    199201                                </td>
Note: See TracChangeset for help on using the changeset viewer.