Plugin Directory

Changeset 3249844


Ignore:
Timestamp:
03/03/2025 05:04:50 PM (13 months ago)
Author:
chatbase
Message:

Release version 1.0.4

Location:
chatbase
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • chatbase/tags/1.0.4/chatbase.php

    r3006988 r3249844  
    55 * Plugin URI: https://www.chatbase.co
    66 * Description: Embed your Chatbase chatbot on any Wordpress site.
    7  * Version: 1.0.3
     7 * Version: 1.0.4
    88 * Author: Chatbase
    99 * Author URI: https://www.chatbase.co/
     
    130130{
    131131    $handle = 'chatbot-script';
     132    $chatbase_id = get_option('chatbase_id');
     133   
     134    wp_register_script($handle, '', [], '', true);
     135    wp_enqueue_script($handle);
    132136
    133     $script_url = 'https://www.chatbase.co/embed.min.js';
    134 
    135     $chatbase_id = get_option('chatbase_id');
    136 
    137     // Enqueue the script
    138     wp_enqueue_script(
    139         $handle,
    140         $script_url,
    141         array(), // Dependencies (if any)
    142         null, // Version number (null for no version)
    143         true // Add script in the footer
    144     );
    145 
    146     // Pass data to the script
    147     wp_localize_script(
    148         $handle,
    149         'embeddedChatbotConfig',
    150         array(
    151             'chatbotId' => esc_attr($chatbase_id),
    152             'domain' => 'www.chatbase.co',
    153         )
    154     );
     137    if (empty($chatbase_id)) {
     138        wp_add_inline_script($handle,
     139            'console.log("Chatbase ID is not configured. Please enter your Chatbot ID in the WordPress admin settings.");'
     140        );
     141        if (defined('WP_DEBUG') && WP_DEBUG) {
     142            error_log('Chatbase: Chatbot ID is not configured');
     143        }
     144        return;
     145    }
     146   
     147    $custom_script = '(function() {
     148        if (!window.chatbase || window.chatbase("getState") !== "initialized") {
     149            window.chatbase = (...arguments) => {
     150                if (!window.chatbase.q) {
     151                    window.chatbase.q = []
     152                }
     153                window.chatbase.q.push(arguments)
     154            };
     155            window.chatbase = new Proxy(window.chatbase, {
     156                get(target, prop) {
     157                    if (prop === "q") {
     158                        return target.q
     159                    }
     160                    return (...args) => target(prop, ...args)
     161                }
     162            })
     163        }
     164        const onLoad = function() {
     165            const script = document.createElement("script");
     166            script.src = "https://www.chatbase.co/embed.min.js";
     167            script.id = "' . esc_js($chatbase_id) . '";
     168            script.domain = "www.chatbase.co";
     169            document.body.appendChild(script)
     170        };
     171        if (document.readyState === "complete") {
     172            onLoad()
     173        } else {
     174            window.addEventListener("load", onLoad)
     175        }
     176    })();';
     177   
     178    wp_add_inline_script($handle, $custom_script);
    155179}
    156180
  • chatbase/tags/1.0.4/readme.txt

    r3006988 r3249844  
    33Tags: chatbase, chatbots, ai
    44Requires at least: 4.7
    5 Tested up to: 6.4.2
    6 Stable tag: 1.0.3
     5Tested up to: 6.7.2
     6Stable tag: 1.0.4
    77Requires PHP: 7.0
    88License: GPLv2
     
    4141= 1.0.3 =
    4242* Updated to latest Chatbase embed script.
     43
     44= 1.0.4 =
     45* Improved script loading using WordPress best practices
     46* Updated to latest Chatbase embed script.
     47* Enhanced script placement in footer for better performance
  • chatbase/trunk/chatbase.php

    r3006988 r3249844  
    55 * Plugin URI: https://www.chatbase.co
    66 * Description: Embed your Chatbase chatbot on any Wordpress site.
    7  * Version: 1.0.3
     7 * Version: 1.0.4
    88 * Author: Chatbase
    99 * Author URI: https://www.chatbase.co/
     
    130130{
    131131    $handle = 'chatbot-script';
     132    $chatbase_id = get_option('chatbase_id');
     133   
     134    wp_register_script($handle, '', [], '', true);
     135    wp_enqueue_script($handle);
    132136
    133     $script_url = 'https://www.chatbase.co/embed.min.js';
    134 
    135     $chatbase_id = get_option('chatbase_id');
    136 
    137     // Enqueue the script
    138     wp_enqueue_script(
    139         $handle,
    140         $script_url,
    141         array(), // Dependencies (if any)
    142         null, // Version number (null for no version)
    143         true // Add script in the footer
    144     );
    145 
    146     // Pass data to the script
    147     wp_localize_script(
    148         $handle,
    149         'embeddedChatbotConfig',
    150         array(
    151             'chatbotId' => esc_attr($chatbase_id),
    152             'domain' => 'www.chatbase.co',
    153         )
    154     );
     137    if (empty($chatbase_id)) {
     138        wp_add_inline_script($handle,
     139            'console.log("Chatbase ID is not configured. Please enter your Chatbot ID in the WordPress admin settings.");'
     140        );
     141        if (defined('WP_DEBUG') && WP_DEBUG) {
     142            error_log('Chatbase: Chatbot ID is not configured');
     143        }
     144        return;
     145    }
     146   
     147    $custom_script = '(function() {
     148        if (!window.chatbase || window.chatbase("getState") !== "initialized") {
     149            window.chatbase = (...arguments) => {
     150                if (!window.chatbase.q) {
     151                    window.chatbase.q = []
     152                }
     153                window.chatbase.q.push(arguments)
     154            };
     155            window.chatbase = new Proxy(window.chatbase, {
     156                get(target, prop) {
     157                    if (prop === "q") {
     158                        return target.q
     159                    }
     160                    return (...args) => target(prop, ...args)
     161                }
     162            })
     163        }
     164        const onLoad = function() {
     165            const script = document.createElement("script");
     166            script.src = "https://www.chatbase.co/embed.min.js";
     167            script.id = "' . esc_js($chatbase_id) . '";
     168            script.domain = "www.chatbase.co";
     169            document.body.appendChild(script)
     170        };
     171        if (document.readyState === "complete") {
     172            onLoad()
     173        } else {
     174            window.addEventListener("load", onLoad)
     175        }
     176    })();';
     177   
     178    wp_add_inline_script($handle, $custom_script);
    155179}
    156180
  • chatbase/trunk/readme.txt

    r3006988 r3249844  
    33Tags: chatbase, chatbots, ai
    44Requires at least: 4.7
    5 Tested up to: 6.4.2
    6 Stable tag: 1.0.3
     5Tested up to: 6.7.2
     6Stable tag: 1.0.4
    77Requires PHP: 7.0
    88License: GPLv2
     
    4141= 1.0.3 =
    4242* Updated to latest Chatbase embed script.
     43
     44= 1.0.4 =
     45* Improved script loading using WordPress best practices
     46* Updated to latest Chatbase embed script.
     47* Enhanced script placement in footer for better performance
Note: See TracChangeset for help on using the changeset viewer.