Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/chatbot/addons/automator/build/index.asset.php
+++ b/chatbot/addons/automator/build/index.asset.php
@@ -4,5 +4,5 @@
'react-jsx-runtime',
'wp-element'
),
- 'version' => '07502fcd9964309c8b75'
+ 'version' => 'fb8d124beab3520a73d9'
);
--- a/chatbot/addons/automator/includes/actions/email-actions.php
+++ b/chatbot/addons/automator/includes/actions/email-actions.php
@@ -59,7 +59,7 @@
$body = isset( $config_values['body'] ) ? (string) $config_values['body'] : '';
$template_id = isset( $config_values['template_id'] ) ? absint( $config_values['template_id'] ) : 0;
$from_email = isset( $config_values['from_email'] ) ? $this->parse_tokens( $config_values['from_email'], $trigger_data ) : get_option( 'admin_email' );
- $from_name = isset( $config_values['from_name'] ) ? $this->parse_tokens( $config_values['from_name'], $trigger_data ) : get_option( 'blogname' );
+ $from_name = isset( $config_values['from_name'] ) ? $this->parse_tokens( $config_values['from_name'], $trigger_data ) : wp_specialchars_decode( (string) get_option( 'blogname' ), ENT_QUOTES );
$cc = isset( $config_values['cc_email'] ) ? (string) $config_values['cc_email'] : '';
$bcc = isset( $config_values['bcc_email'] ) ? (string) $config_values['bcc_email'] : '';
$reply_to = isset( $config_values['reply_to'] ) ? $this->parse_tokens( $config_values['reply_to'], $trigger_data ) : '';
--- a/chatbot/addons/automator/includes/templates/support-page.php
+++ b/chatbot/addons/automator/includes/templates/support-page.php
@@ -55,7 +55,7 @@
/* Support Cards */
.wpbot-support-grid {
display: grid;
- grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
+ grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
gap: 30px;
margin-bottom: 60px;
}
--- a/chatbot/admin_ui.php
+++ b/chatbot/admin_ui.php
@@ -29,7 +29,7 @@
<div class="qcld-wp-chatbot-wrap-header">
- <div class="qcld-wp-chatbot-wrap-header-logo"><a href="#" class="qcld-wp-chatbot-wrap-site__logo"><img src="<?php echo esc_url( QCLD_wpCHATBOT_IMG_URL . '/chatbot.png' ); ?>" alt="Dialogflow CX"> WPBot Control Panel </a>
+ <div class="qcld-wp-chatbot-wrap-header-logo"><a href="#" class="qcld-wp-chatbot-wrap-site__logo"><img src="<?php echo esc_url( qcld_wpbot_brand_logo_url() ); ?>" alt="Dialogflow CX"> WPBot Control Panel </a>
<p><strong>Core Version:</strong> v<?php echo esc_attr(QCLD_wpCHATBOT_VERSION); ?></p>
</div>
<ul class="qcld-wp-chatbot-wrap-version-wrapper">
@@ -443,7 +443,7 @@
<div class="check-icon"><svg viewBox="0 0 14 14"><path d="M4 7.2L6.2 9.4L10 5" /></svg></div>
<div class="icon-wrapper"><i class="dashicons dashicons-search" style="font-size:24px;width:24px;height:24px;"></i></div>
<h4><?php esc_html_e('Enable Chatbot On WordPress search', 'chatbot'); ?></h4>
- <p><?php esc_html_e('Enable Chatbot on WordPress search pages.', 'chatbot'); ?></p>
+ <p><?php esc_html_e('Add a chat button next to the WordPress search form.', 'chatbot'); ?></p>
</div>
</label>
@@ -465,7 +465,7 @@
<div class="check-icon"><svg viewBox="0 0 14 14"><path d="M4 7.2L6.2 9.4L10 5" /></svg></div>
<div class="icon-wrapper"><i class="dashicons dashicons-dismiss" style="font-size:24px;width:24px;height:24px;"></i></div>
<h4><?php esc_html_e('Disable Floating Button', 'chatbot'); ?></h4>
- <p><?php esc_html_e('Hide the chatbot floating icon from your website.', 'chatbot'); ?></p>
+ <p><?php esc_html_e('Hide the chat button. Open the chat with a link or button that has the class wpbot-click-chat.', 'chatbot'); ?></p>
</div>
</label>
<label class="wpbot-checkbox-card">
@@ -769,7 +769,7 @@
</h4>
<input type="text" class="form-control qc-opt-dcs-font"
name="qlcd_wp_chatbot_host"
- value="<?php echo esc_attr((get_option('qlcd_wp_chatbot_host') != '' ? get_option('qlcd_wp_chatbot_host') : 'Our Store') ); ?>">
+ value="<?php echo esc_attr((get_option('qlcd_wp_chatbot_host') != '' ? get_option('qlcd_wp_chatbot_host') : qcld_wpbot_default_host_name()) ); ?>">
</div>
<div class="form-group">
<h4 class="qc-opt-title">
@@ -991,11 +991,11 @@
</div>
<div class="form-group">
<h4 class="qc-opt-title">
- <?php esc_html_e('Your email was sent successfully.Thanks!', 'chatbot'); ?>
+ <?php esc_html_e('Your email was sent successfully. Thanks!', 'chatbot'); ?>
</h4>
<input type="text" class="form-control qc-opt-dcs-font"
name="qlcd_wp_chatbot_email_sent"
- value="<?php echo esc_attr((get_option('qlcd_wp_chatbot_email_sent') != '' ? get_option('qlcd_wp_chatbot_email_sent') : 'Your email was sent successfully.Thanks!')); ?> ">
+ value="<?php echo esc_attr((get_option('qlcd_wp_chatbot_email_sent') != '' ? get_option('qlcd_wp_chatbot_email_sent') : 'Your email was sent successfully. Thanks!')); ?>">
</div>
<div class="form-group">
<h4 class="qc-opt-title">
@@ -1317,11 +1317,23 @@
<div class="row">
<div class="col-xs-12">
+ <?php
+ // New chat button design (chatbot module): design, finish, color, motion, floating box.
+ do_action( 'qcld_wpbot_chat/launcher_settings' );
+ ?>
<h3 class="qcld-wpbot-main-tabs-title">
<?php esc_html_e('WPBot Icon', 'chatbot'); ?>
</h3>
<div class="cxsc-settings-blocks">
<ul class="radio-list">
+ <li>
+ <label for="wp_chatbot_icon_molecule" class="qc-opt-dcs-font"><img src="<?php echo esc_url(QCLD_wpCHATBOT_IMG_URL); ?>/icon-molecule.svg" alt="">
+ <input id="wp_chatbot_icon_molecule" type="radio"
+ name="wp_chatbot_icon" <?php echo(get_option('wp_chatbot_icon') == 'icon-molecule.svg' ? esc_attr('checked' ): ''); ?>
+ value="<?php echo esc_attr('icon-molecule.svg'); ?>">
+ <?php esc_html_e('Molecule (new design)', 'chatbot'); ?>
+ </label>
+ </li>
<li>
<label for="wp_chatbot_icon_0" class="qc-opt-dcs-font"><img src="<?php echo esc_url(QCLD_wpCHATBOT_IMG_URL); ?>/icon-0.png" alt="">
@@ -1355,7 +1367,7 @@
<input id="wp_chatbot_icon_3" type="radio"
name="wp_chatbot_icon" <?php echo(get_option('wp_chatbot_icon') == 'icon-3.png' ? esc_attr('checked' ): ''); ?>
value="<?php echo esc_attr('icon-3.png'); ?>">
- <?php esc_html_e('Icon - 3', 'chatbot'); ?>
+ <?php esc_html_e('Chat bubble', 'chatbot'); ?>
</label>
</li>
<li>
@@ -1409,7 +1421,7 @@
<input id="wp_chatbot_icon_9" type="radio"
name="wp_chatbot_icon" <?php echo(get_option('wp_chatbot_icon') == 'icon-9.png' ? esc_attr('checked' ): ''); ?>
value="<?php echo esc_attr('icon-9.png'); ?>">
- <?php esc_html_e('Icon - 9', 'chatbot'); ?>
+ <?php esc_html_e('Smiling bubble', 'chatbot'); ?>
</label>
</li>
<li>
@@ -1418,7 +1430,7 @@
<input id="wp_chatbot_icon_10" type="radio"
name="wp_chatbot_icon" <?php echo(get_option('wp_chatbot_icon') == 'icon-10.png' ? esc_attr('checked' ): ''); ?>
value="<?php echo esc_attr('icon-10.png'); ?>">
- <?php esc_html_e('Icon - 10', 'chatbot'); ?>
+ <?php esc_html_e('Two bubbles', 'chatbot'); ?>
</label>
</li>
<li>
@@ -1427,7 +1439,7 @@
<input id="wp_chatbot_icon_11" type="radio"
name="wp_chatbot_icon" <?php echo(get_option('wp_chatbot_icon') == 'icon-11.png' ? esc_attr('checked' ): ''); ?>
value="<?php echo esc_attr('icon-11.png'); ?>">
- <?php esc_html_e('Icon - 11', 'chatbot'); ?>
+ <?php esc_html_e('Headset', 'chatbot'); ?>
</label>
</li>
<li>
@@ -1457,7 +1469,7 @@
$wp_chatbot_custom_icon_path = esc_url(QCLD_wpCHATBOT_IMG_URL) . 'custom.png';
}
?>
- <label for="wp_chatbot_custom_icon_input" class="qc-opt-dcs-font"> <img id="wp_chatbot_custom_icon_src "
+ <label for="wp_chatbot_custom_icon_input" class="qc-opt-dcs-font"> <img id="wp_chatbot_custom_icon_src"
src="<?php echo esc_url($wp_chatbot_custom_icon_path); ?>" alt=" ">
<input id="wp_chatbot_custom_icon_input" type="radio"
name="wp_chatbot_icon"
@@ -1498,117 +1510,7 @@
</div>
</div>
</div>
- <!-- ===== Custom Icon Video / YouTube ===== -->
- <div class="row">
- <div class="col-xs-12">
- <div class="form-group">
- <h4 class="qc-opt-title"><?php echo esc_html__('Custom Icon Video / YouTube Link', 'chatbot'); ?></h4>
- <p style="margin-bottom:8px;"><?php echo esc_html__('Upload a short video file or paste a YouTube embed URL to use instead of the wpbot icon.', 'chatbot'); ?></p>
- <div class="cxsc-settings-blocks">
-
- <?php
- $wp_chatbot_icon_video = get_option('wp_chatbot_icon_video', '');
- $is_youtube = (strpos($wp_chatbot_icon_video, 'youtube.com') !== false || strpos($wp_chatbot_icon_video, 'youtu.be') !== false);
- $is_video = !$is_youtube && $wp_chatbot_icon_video !== '';
- ?>
-
- <!-- Video Upload -->
- <p style="font-weight:600;margin-bottom:4px;"><?php echo esc_html__('Upload Video File', 'chatbot'); ?></p>
- <input type="hidden"
- name="wp_chatbot_icon_video"
- id="wp_chatbot_icon_video"
- value="<?php echo esc_url($wp_chatbot_icon_video); ?>" />
- <button type="button" id="wp_chatbot_icon_video_btn" class="button">
- <?php echo esc_html__('Upload Video', 'chatbot'); ?>
- </button>
- <?php if ($is_video): ?>
- <span style="margin-left:8px;vertical-align:middle;">
- <video src="<?php echo esc_url($wp_chatbot_icon_video); ?>" width="80" height="80" style="border-radius:50%;object-fit:cover;" muted loop autoplay playsinline></video>
- </span>
- <?php endif; ?>
- <button type="button" id="wp_chatbot_icon_video_clear_btn" class="button" style="margin-left:6px;<?php echo ($wp_chatbot_icon_video === '' || $is_youtube) ? 'display:none;' : ''; ?>">
- <?php echo esc_html__('Remove Video', 'chatbot'); ?>
- </button>
-
- <!-- YouTube URL -->
- <p style="font-weight:600;margin-top:12px;margin-bottom:4px;"><?php echo esc_html__('— or — YouTube Embed URL', 'chatbot'); ?></p>
- <?php $youtube_url_val = $is_youtube ? esc_url($wp_chatbot_icon_video) : ''; ?>
- <input type="url"
- name="wp_chatbot_icon_youtube_url"
- id="wp_chatbot_icon_youtube_url"
- class="regular-text"
- placeholder="https://www.youtube.com/embed/VIDEO_ID"
- value="<?php echo esc_url( $youtube_url_val ); ?>" />
- <button type="button" id="wp_chatbot_icon_youtube_url_clear_btn" class="button" style="margin-left:6px;<?php echo ($youtube_url_val === '' ? 'display:none;' : ''); ?>">
- <?php echo esc_html__('Remove YouTube URL', 'chatbot'); ?>
- </button>
- <p class="description"><?php echo esc_html__('Paste the YouTube embed URL (e.g. https://www.youtube.com/embed/xxxxx). This will override the uploaded video above.', 'chatbot'); ?></p>
-
- <p style="font-weight:600;margin-top:14px;margin-bottom:4px;"><?php echo esc_html__('Autoplay Delay (seconds)', 'chatbot'); ?></p>
- <input type="number"
- name="wp_chatbot_icon_video_delay"
- id="wp_chatbot_icon_video_delay"
- class="small-text"
- min="0"
- max="60"
- step="1"
- value="<?php echo absint( get_option('wp_chatbot_icon_video_delay', 0) ); ?>" />
- <p class="description"><?php echo esc_html__('Wait this many seconds after page load before starting the video. Set to 0 for immediate autoplay.', 'chatbot'); ?></p>
-
- </div>
- </div>
- </div>
- </div>
- <!-- ===== /Custom Icon Video / YouTube ===== -->
- <script>
- (function($){
- $(document).ready(function(){
- // Video upload via WP Media Library
- $('#wp_chatbot_icon_video_btn').on('click', function(e){
- e.preventDefault();
- var frame = wp.media({
- title: '<?php echo esc_js(__('Select or Upload Video', 'chatbot')); ?>',
- button: { text: '<?php echo esc_js(__('Use this video', 'chatbot')); ?>' },
- multiple: false,
- library: { type: 'video' }
- });
- frame.on('select', function(){
- var attachment = frame.state().get('selection').first().toJSON();
- $('#wp_chatbot_icon_video').val(attachment.url);
- $('#wp_chatbot_icon_youtube_url').val('');
- $('#wp_chatbot_icon_youtube_url_clear_btn').hide();
- $('#wp_chatbot_icon_video_clear_btn').show();
- });
- frame.open();
- });
-
- // Clear uploaded video
- $('#wp_chatbot_icon_video_clear_btn').on('click', function(){
- $('#wp_chatbot_icon_video').val('');
- $(this).hide();
- });
-
- // Show/hide Remove YouTube URL button dynamically
- $('#wp_chatbot_icon_youtube_url').on('input keyup change', function(){
- if ($(this).val().trim() !== '') {
- $('#wp_chatbot_icon_youtube_url_clear_btn').show();
- } else {
- $('#wp_chatbot_icon_youtube_url_clear_btn').hide();
- }
- });
-
- // Clear YouTube URL
- $('#wp_chatbot_icon_youtube_url_clear_btn').on('click', function(){
- $('#wp_chatbot_icon_youtube_url').val('');
- var currentVideoVal = $('#wp_chatbot_icon_video').val();
- if (currentVideoVal.indexOf('youtube.com') !== -1 || currentVideoVal.indexOf('youtu.be') !== -1) {
- $('#wp_chatbot_icon_video').val('');
- }
- $(this).hide();
- });
- });
- })(jQuery);
- </script>
+ <?php // The custom icon video / YouTube option was removed (owner, 18 November 2026): the button shows the icon selected above. ?>
<div class="row">
@@ -1628,6 +1530,37 @@
<?php esc_html_e('Default Agent', 'chatbot'); ?>
</label>
</li>
+ <?php // Five more agent pictures (owner, 18 November 2026). ?>
+ <li>
+ <label for="wp_chatbot_agent_image_agent_1" class="qc-opt-dcs-font"> <img src="<?php echo esc_url( QCLD_wpCHATBOT_IMG_URL . 'agent-1.png' ); ?>" alt="">
+ <input id="wp_chatbot_agent_image_agent_1" type="radio" name="wp_chatbot_agent_image" <?php checked( 'agent-1.png', (string) get_option( 'wp_chatbot_agent_image' ) ); ?> value="agent-1.png">
+ <?php esc_html_e( 'Support agent, teal', 'chatbot' ); ?>
+ </label>
+ </li>
+ <li>
+ <label for="wp_chatbot_agent_image_agent_2" class="qc-opt-dcs-font"> <img src="<?php echo esc_url( QCLD_wpCHATBOT_IMG_URL . 'agent-2.png' ); ?>" alt="">
+ <input id="wp_chatbot_agent_image_agent_2" type="radio" name="wp_chatbot_agent_image" <?php checked( 'agent-2.png', (string) get_option( 'wp_chatbot_agent_image' ) ); ?> value="agent-2.png">
+ <?php esc_html_e( 'Support agent, blue', 'chatbot' ); ?>
+ </label>
+ </li>
+ <li>
+ <label for="wp_chatbot_agent_image_agent_3" class="qc-opt-dcs-font"> <img src="<?php echo esc_url( QCLD_wpCHATBOT_IMG_URL . 'agent-3.png' ); ?>" alt="">
+ <input id="wp_chatbot_agent_image_agent_3" type="radio" name="wp_chatbot_agent_image" <?php checked( 'agent-3.png', (string) get_option( 'wp_chatbot_agent_image' ) ); ?> value="agent-3.png">
+ <?php esc_html_e( 'Friendly robot', 'chatbot' ); ?>
+ </label>
+ </li>
+ <li>
+ <label for="wp_chatbot_agent_image_agent_4" class="qc-opt-dcs-font"> <img src="<?php echo esc_url( QCLD_wpCHATBOT_IMG_URL . 'agent-4.png' ); ?>" alt="">
+ <input id="wp_chatbot_agent_image_agent_4" type="radio" name="wp_chatbot_agent_image" <?php checked( 'agent-4.png', (string) get_option( 'wp_chatbot_agent_image' ) ); ?> value="agent-4.png">
+ <?php esc_html_e( 'Assistant, purple', 'chatbot' ); ?>
+ </label>
+ </li>
+ <li>
+ <label for="wp_chatbot_agent_image_agent_5" class="qc-opt-dcs-font"> <img src="<?php echo esc_url( QCLD_wpCHATBOT_IMG_URL . 'agent-5.png' ); ?>" alt="">
+ <input id="wp_chatbot_agent_image_agent_5" type="radio" name="wp_chatbot_agent_image" <?php checked( 'agent-5.png', (string) get_option( 'wp_chatbot_agent_image' ) ); ?> value="agent-5.png">
+ <?php esc_html_e( 'Assistant, orange', 'chatbot' ); ?>
+ </label>
+ </li>
<li>
<?php
--- a/chatbot/class-plugin-deactivate-feedback.php
+++ b/chatbot/class-plugin-deactivate-feedback.php
@@ -249,7 +249,7 @@
'has_details' => true,
),
);
- $form['email'] = __( 'Email Address (Optional)', 'chatbot' );
+ $form['email'] = __( 'Email Address', 'chatbot' );
$form['details'] = __( 'Please share a few details so we can improve', 'chatbot' );
return $form;
}
@@ -362,9 +362,14 @@
<span><?php echo esc_html( $form['email'] ?? __( 'Email Address', 'chatbot' ) ); ?></span>
<span class="wpb-goodbye-badge-optional"><?php esc_html_e( 'Optional', 'chatbot' ); ?></span>
</label>
+ <label class="wpb-goodbye-contact">
+ <input type="checkbox" id="wpb-goodbye-contact-ok" name="wpb-goodbye-contact-ok" value="1" />
+ <span><?php esc_html_e( 'You may contact me about this feedback', 'chatbot' ); ?></span>
+ </label>
<div class="wpb-goodbye-input-wrap">
- <span class="dashicons dashicons-email-alt wpb-goodbye-input-icon"></span>
- <input type="email" name="wpb-goodbye-email" id="wpb-goodbye-email-input" class="wpb-goodbye-input" value="<?php echo esc_attr( get_option( 'admin_email' ) ); ?>" placeholder="email@example.com" />
+ <span class="dashicons dashicons-email-alt wpb-goodbye-input-icon" aria-hidden="true"></span>
+ <?php // Opt-in: the address is not filled in, and is sent only when the box above is ticked. ?>
+ <input type="email" name="wpb-goodbye-email" id="wpb-goodbye-email-input" class="wpb-goodbye-input" value="" placeholder="email@example.com" autocomplete="email" disabled />
</div>
</div>
<div id="wpbot_deactivation_error"></div>
@@ -691,6 +696,10 @@
display: flex;
align-items: center;
}
+ .wpb-goodbye-input-wrap input.wpb-goodbye-input[type="email"]:disabled {
+ background: #f8fafc;
+ cursor: not-allowed;
+ }
.wpb-goodbye-input-icon {
position: absolute;
left: 10px;
@@ -698,10 +707,24 @@
font-size: 17px;
pointer-events: none;
}
- .wpb-goodbye-input {
+ .wpb-goodbye-contact {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ margin: 0 0 8px;
+ font-size: 13px;
+ color: #334155;
+ cursor: pointer;
+ }
+ .wpb-goodbye-contact input[type="checkbox"] {
+ margin: 0;
+ }
+ .wpb-goodbye-input,
+ .wpb-goodbye-input-wrap input.wpb-goodbye-input[type="email"] {
width: 100%;
border: 1.5px solid #cbd5e1;
border-radius: 8px;
+ /* More specific than WordPress's input[type=email] padding, which put the icon on the first letter. */
padding: 9px 12px 9px 34px;
font-size: 13.5px;
color: #1e293b;
@@ -918,13 +941,23 @@
}
});
+ // The email field is used only when the visitor agrees to be contacted.
+ $(document).on("change", "#wpb-goodbye-form-" + pluginName + " #wpb-goodbye-contact-ok", function(){
+ var $email = $modal.find("#wpb-goodbye-email-input");
+ $email.prop("disabled", !this.checked);
+ if (this.checked) {
+ $email.trigger("focus");
+ }
+ });
+
// Submit and Deactivate
$(document).on("click", "#wpb-goodbye-form-" + pluginName + " #wpb-submit-form", function(e){
e.preventDefault();
var selectedOption = $modal.find("input[name=wpb-goodbye-option-choice]:checked").val() || "";
var details = $modal.find("#wpb-goodbye-reasons-input").val() || "";
- var email = $modal.find("#wpb-goodbye-email-input").val() || "";
+ var contactOk = $modal.find("#wpb-goodbye-contact-ok").is(":checked");
+ var email = contactOk ? ($modal.find("#wpb-goodbye-email-input").val() || "") : "";
if (!selectedOption && !details) {
$modal.find("#wpbot_deactivation_error")
@@ -976,9 +1009,12 @@
update_option( 'wpbot_deactivation_details_' . $this->plugin_name, $details );
}
- if( isset( $_POST['email'] ) ) {
- $email = sanitize_email( wp_unslash( $_POST['email'] ) );
+ // Only an address the admin typed and agreed to be contacted at (the form sends none otherwise).
+ $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : '';
+ if ( '' !== $email && is_email( $email ) ) {
update_option( 'wpbot_deactivation_email_' . $this->plugin_name, $email );
+ } else {
+ delete_option( 'wpbot_deactivation_email_' . $this->plugin_name );
}
echo 'success';
--- a/chatbot/functions.php
+++ b/chatbot/functions.php
@@ -5,6 +5,90 @@
*/
if (!defined('ABSPATH')) exit; // Exit if accessed directly
+if ( ! function_exists( 'qcld_wpbot_no_icon_video' ) ) {
+ /**
+ * The custom icon video / YouTube option is removed (owner, 18 November 2026): the button shows
+ * the icon selected in the Icons list. A saved video stays in the database, unused.
+ *
+ * @return string
+ */
+ function qcld_wpbot_no_icon_video() {
+ return '';
+ }
+ add_filter( 'pre_option_wp_chatbot_icon_video', 'qcld_wpbot_no_icon_video' );
+}
+
+if ( ! function_exists( 'qcld_wpbot_existing_icon' ) ) {
+ /**
+ * A built-in chat icon whose file no longer ships (a name saved by an older version, for example
+ * wpbot-logo.gif) shows the default icon instead of a broken image (owner, 17 November 2026).
+ * Uploaded icons ("custom.png" with their own address) are not touched.
+ *
+ * @param mixed $icon Saved icon file name.
+ * @return mixed
+ */
+ function qcld_wpbot_existing_icon( $icon ) {
+ // Only what visitors see: the settings screen shows the stored choice, so saving it never
+ // replaces the site owner's selection with the default (owner, 18 November 2026).
+ if ( is_admin() && ! wp_doing_ajax() ) {
+ return $icon;
+ }
+ if ( ! is_string( $icon ) || '' === $icon || 'custom.png' === $icon || false !== strpos( $icon, '/' ) || ! defined( 'QCLD_wpCHATBOT_PLUGIN_DIR_PATH' ) ) {
+ return $icon;
+ }
+ return file_exists( trailingslashit( QCLD_wpCHATBOT_PLUGIN_DIR_PATH ) . 'images/' . $icon ) ? $icon : 'icon-0.png';
+ }
+ add_filter( 'option_wp_chatbot_icon', 'qcld_wpbot_existing_icon' );
+}
+
+if ( ! function_exists( 'qcld_wpbot_user_data_in_use' ) ) {
+ /**
+ * Whether a visitor's details can reach the User Data screen: the greeting asks for an email, or
+ * details are stored already. Without either, the ChatBot header leaves the User Data tab out
+ * (same as WPBot Pro, which also counts its phone question and Email Subscription button).
+ *
+ * @return bool
+ */
+ function qcld_wpbot_user_data_in_use() {
+ $skipped = false;
+ foreach ( array( 'skip_wp_greetings', 'skip_wp_greetings_donot_show_menu', 'skip_wp_greetings_trigger_intent' ) as $option ) {
+ if ( '1' === (string) get_option( $option ) ) {
+ $skipped = true;
+ }
+ }
+ // WPBot Free's chat asks for the email with enable_asking_for_email (ask_email_wp_greetings is saved beside it).
+ $in_use = ! $skipped && ( '1' === (string) get_option( 'enable_asking_for_email' ) || '1' === (string) get_option( 'ask_email_wp_greetings' ) );
+ if ( ! $in_use ) {
+ global $wpdb;
+ $table = $wpdb->prefix . 'wpbot_subscription';
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- One row, only when the greeting asks for no email.
+ if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) ) ) === $table ) {
+ $in_use = (bool) $wpdb->get_var( "SELECT 1 FROM {$table} LIMIT 1" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- The plugin's own table name.
+ }
+ }
+ /** Whether the User Data tab is shown (same filter as WPBot Pro). */
+ return (bool) apply_filters( 'qcld_wpbot_user_data_tab', $in_use );
+ }
+}
+
+if ( ! function_exists( 'qcld_wpbot_existing_agent_image' ) ) {
+ /**
+ * The same for the agent image next to the bot's messages: a built-in picture whose file no
+ * longer ships shows the default agent instead of a broken image. Uploaded pictures
+ * ("custom-agent.png" with their own address) are not touched. Same as WPBot Pro.
+ *
+ * @param mixed $image Saved agent image file name.
+ * @return mixed
+ */
+ function qcld_wpbot_existing_agent_image( $image ) {
+ if ( ! is_string( $image ) || '' === $image || 'custom-agent.png' === $image || false !== strpos( $image, '/' ) || ! defined( 'QCLD_wpCHATBOT_PLUGIN_DIR_PATH' ) ) {
+ return $image;
+ }
+ return file_exists( trailingslashit( QCLD_wpCHATBOT_PLUGIN_DIR_PATH ) . 'images/' . $image ) ? $image : 'agent-0.png';
+ }
+ add_filter( 'option_wp_chatbot_agent_image', 'qcld_wpbot_existing_agent_image' );
+}
+
/**
* Plugin-relative path of a front-end asset: the .min copy built for releases, unless SCRIPT_DEBUG is on.
*/
@@ -49,36 +133,115 @@
}
}
-function qcld_custom_search_form( $form ) {
- // Add a hidden input to limit search to 'product' post type
- $wp_chatbot_custom_agent_path = class_exists( 'qcld_wb_Chatbot_free' ) ? qcld_wb_Chatbot_free::qcld_wb_chatbot_get_instance()->qcld_wb_chatbot_agent_icon() : QCLD_wpCHATBOT_IMG_URL . 'agent-0.png';
- $hidden_field = '<a class="wp-chatbot qc_wpbot_chat_link" id="wp-chatbot-search-btn" data-search-type="product" data-search-term="" style="max-height: 50px; margin-left: 10px;padding: 0 !important;position: absolute;top: -9px;right: -60px;"><img src="'. esc_url($wp_chatbot_custom_agent_path) .'" alt=""></a>';
- $block_content = str_replace( '</form>', $hidden_field . '</form>', $form );
- return $block_content;
-}
-if(get_option('wpbot_enable_on_search') == 1 && (get_option('disable_floating_button') != '1') && get_option('disable_wp_chatbot') != 1 ){
- add_filter( 'get_search_form', 'qcld_custom_search_form' );
- add_filter( 'render_block_core/search', 'qcld_modify_gutenberg_search_block', 10, 2 );
+/**
+ * The chat button added next to WordPress search forms ("Enable Chatbot On WordPress search").
+ *
+ * It carries the class wpbot-click-chat, which the chatbot's launcher and the widget both open the
+ * chat on (QA, 18 November 2026: the old link had no handler until the widget loaded, so a click did
+ * nothing, and its image showed at full size outside the form). Sized by css/wpbot-front-host.css.
+ *
+ * @return string Button HTML.
+ */
+function qcld_wpbot_search_chat_button() {
+ $icon = class_exists( 'qcld_wb_Chatbot_free' ) ? qcld_wb_Chatbot_free::qcld_wb_chatbot_get_instance()->qcld_wb_chatbot_agent_icon() : QCLD_wpCHATBOT_IMG_URL . 'agent-0.png';
+ $label = __( 'Open the chat', 'chatbot' );
+ return '<button type="button" class="wp-chatbot qc_wpbot_chat_link wpbot-click-chat wpbot-search-chat-btn" id="wp-chatbot-search-btn" aria-label="' . esc_attr( $label ) . '" title="' . esc_attr( $label ) . '">'
+ . '<img src="' . esc_url( $icon ) . '" alt="" width="40" height="40" loading="lazy" decoding="async">'
+ . '</button>';
}
+/**
+ * Whether to add the chat button to search forms on this page: the option is on, the chatbot is on
+ * and it shows on this page (a button that opens nothing is worse than none).
+ *
+ * @return bool
+ */
+function qcld_wpbot_search_button_on() {
+ static $on = null;
+ if ( is_admin() || ! did_action( 'wp' ) ) {
+ return false; // Too early to know the page (not cached, so a later form still gets the button).
+ }
+ if ( null === $on ) {
+ $on = qcld_wpbot_free_may_load();
+ }
+ return $on;
+}
+
+function qcld_custom_search_form( $form ) {
+ if ( ! qcld_wpbot_search_button_on() || false === strpos( (string) $form, '</form>' ) || false !== strpos( (string) $form, 'wp-chatbot-search-btn' ) ) {
+ return $form;
+ }
+ $pos = strrpos( $form, '</form>' );
+ return substr( $form, 0, $pos ) . qcld_wpbot_search_chat_button() . substr( $form, $pos );
+}
function qcld_modify_gutenberg_search_block( $block_content, $block ) {
- // Add a hidden input to limit search to 'product' post type
- if (get_option('wp_chatbot_agent_image') == "custom-agent.png") {
- $wp_chatbot_custom_agent_path = get_option('wp_chatbot_custom_agent_path');
- } else if (get_option('wp_chatbot_agent_image') != "custom-agent.png") {
- $wp_chatbot_custom_agent_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image');
- } else {
- $wp_chatbot_custom_agent_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png';
+ if ( ! qcld_wpbot_search_button_on() || false !== strpos( (string) $block_content, 'wp-chatbot-search-btn' ) ) {
+ return $block_content;
+ }
+ // Inside the block's flex wrapper, next to its search button.
+ $pos = strrpos( (string) $block_content, '</div></form>' );
+ if ( false === $pos ) {
+ $pos = strrpos( (string) $block_content, '</form>' );
+ }
+ if ( false === $pos ) {
+ return $block_content;
}
- $hidden_field = '<button type="button" class="wp-chatbot qc_wpbot_chat_link" id="wp-chatbot-search-btn" data-search-type="product" data-search-term="" style="max-height: 50px; margin-left: 10px;padding: 0 !important"><img src="'. esc_url($wp_chatbot_custom_agent_path) .'" alt=""></button>';
- // Inject the hidden field before the closing </form> tag
- $block_content = str_replace( '</div></form>', $hidden_field . '</div></form>', $block_content );
- return $block_content;
+ return substr( $block_content, 0, $pos ) . qcld_wpbot_search_chat_button() . substr( $block_content, $pos );
}
-if(get_option('disable_floating_button') != '1'){
- add_action('wp_footer', 'wp_chatbot_load_footer_html');
+
+if ( get_option( 'wpbot_enable_on_search' ) == 1 && get_option( 'disable_wp_chatbot' ) != 1 ) {
+ add_filter( 'get_search_form', 'qcld_custom_search_form' );
+ add_filter( 'render_block_core/search', 'qcld_modify_gutenberg_search_block', 10, 2 );
}
+
+/**
+ * Small front-end stylesheet the page needs before the chat widget loads: the search chat button
+ * and "Disable Floating Button". Kept out of the launcher's deferred files (see
+ * QCLD_WPBot_Free_Chatbot_Adapter::widget_assets()), so it applies at first paint.
+ *
+ * @return void
+ */
+function qcld_wpbot_free_front_host_style() {
+ if ( get_option( 'disable_wp_chatbot' ) == 1 ) {
+ return;
+ }
+ if ( get_option( 'wpbot_enable_on_search' ) != 1 && get_option( 'disable_floating_button' ) != '1' ) {
+ return;
+ }
+ wp_enqueue_style( 'qcld-wpbot-free-front-host', QCLD_wpCHATBOT_PLUGIN_URL . qcld_wpbot_min_asset( 'css/wpbot-front-host.css' ), array(), QCLD_wpCHATBOT_VERSION );
+}
+add_action( 'wp_enqueue_scripts', 'qcld_wpbot_free_front_host_style' );
+
+/**
+ * The launcher also opens the chat from the search chat button and the older chat-link class.
+ *
+ * @param array $config Launcher configuration.
+ * @return array
+ */
+function qcld_wpbot_free_launcher_config( $config ) {
+ if ( isset( $config['trigger'] ) && is_string( $config['trigger'] ) ) {
+ $config['trigger'] .= ', .qc_wpbot_chat_link, #wp-chatbot-search-btn';
+ }
+ return $config;
+}
+add_filter( 'qcld_wpbot_chat/launcher_config', 'qcld_wpbot_free_launcher_config' );
+
+/**
+ * "Disable Floating Button" hides the notification box that belongs to the button, so the widget
+ * need not load by itself to show it.
+ *
+ * @param bool $on Notification shows by itself.
+ * @return bool
+ */
+function qcld_wpbot_free_lazy_notification( $on ) {
+ return get_option( 'disable_floating_button' ) == '1' ? false : $on;
+}
+add_filter( 'qcld_wpbot_chat/lazy_notification', 'qcld_wpbot_free_lazy_notification' );
+
+// "Disable Floating Button" hides only the button (css/wpbot-front-host.css); the chat itself is still
+// printed, so a wpbot-click-chat link or the search chat button opens it.
+add_action('wp_footer', 'wp_chatbot_load_footer_html');
add_action( 'admin_footer', 'qcld_style_for_hide_iframe');
function qcld_style_for_hide_iframe(){
?>
@@ -217,7 +380,11 @@
$wp_chatbot_enable_mobile_screen .= "wp-chatbot-mobile-full-screen";
// }
?>
- <div id="wp-chatbot-chat-container" class="<?php echo esc_attr($wp_chatbot_enable_rtl .' '.$wp_chatbot_enable_mobile_screen); ?>" style="<?php if(get_option('disable_floating_button') == '1'){ echo 'display:none';} ?>">
+ <?php
+ // "Disable Floating Button": hide the button (and its notification box) only, keep the chat.
+ $wp_chatbot_hide_launcher = get_option('disable_floating_button') == '1' ? ' wpbot-hide-launcher' : '';
+ ?>
+ <div id="wp-chatbot-chat-container" class="<?php echo esc_attr($wp_chatbot_enable_rtl .' '.$wp_chatbot_enable_mobile_screen . $wp_chatbot_hide_launcher); ?>">
<div id="wp-chatbot-integration-container">
<div class="wp-chatbot-integration-button-container">
<?php if (get_option('enable_wp_chatbot_skype_floating_icon') == 1) { ?>
@@ -285,7 +452,18 @@
</div>
<?php
//update_option('qlcd_wp_chatbot_notifications','Welcome to WpBot');
- $notifications = qcld_wb_chatbot_func_str_replace(wp_kses_post(maybe_unserialize(get_option('qlcd_wp_chatbot_notifications'))));
+ // The messages are a list: wp_kses_post() on the whole list was a fatal error on PHP 8 that
+ // cut off the rest of the footer (the chat scripts) whenever the floating box was on.
+ $notifications = maybe_unserialize(get_option('qlcd_wp_chatbot_notifications'));
+ $notifications = is_array($notifications) ? $notifications : array((string) $notifications);
+ $first = reset($notifications);
+ if (is_array($first)) {
+ // A list per language (saved by WPBot Pro on a shared site).
+ $locale = get_locale();
+ $notifications = isset($notifications[$locale]) && is_array($notifications[$locale]) ? $notifications[$locale] : $first;
+ }
+ $notifications = qcld_wb_chatbot_func_str_replace(array_map('wp_kses_post', array_values(array_filter($notifications, 'is_string'))));
+ $notifications = $notifications ? $notifications : array('');
?>
@@ -479,7 +657,7 @@
if (get_option('wp_chatbot_show_pages') == 'off') {
- $wp_chatbot_select_pages = unserialize(get_option('wp_chatbot_show_pages_list'));
+ $wp_chatbot_select_pages = maybe_unserialize(get_option('wp_chatbot_show_pages_list'));
if (is_page() && !empty($wp_chatbot_select_pages)) {
if (in_array(get_the_ID(), $wp_chatbot_select_pages) == true) {
@@ -490,16 +668,13 @@
}
}
-
- if(function_exists('is_shop')){
- if (is_shop() || is_cart() || is_checkout() || 'product' == get_post_type()) {
- $wp_chatbot_load = false;
- }
- }
-
}
- if (get_option('wp_chatbot_show_wpcommerce') == 'off') {
-
+ // WooCommerce pages (shop, cart, checkout, products): shown unless this is turned off (default on).
+ // It used to sit inside "Selected Pages Only", which hid every WooCommerce page (QA, 18 November 2026).
+ if (get_option('wp_chatbot_show_wpcommerce') == 'off' && function_exists('is_shop')) {
+ if (is_shop() || is_cart() || is_checkout() || 'product' == get_post_type()) {
+ $wp_chatbot_load = false;
+ }
}
//load wpwbot shortcode template and prevent default wpwbot from footer.
if (is_page()) {
@@ -1049,8 +1224,10 @@
$response['message'] = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_invalid_email'))));
$response['status'] = 'fail';
} else {
+ // Keep the address in User Data, as the greeting's "ask for email" step does.
+ qcld_wpbot_save_email_lead( $name, $email, $refurl, $user_agent );
$primary_color = '#5b4e96';
- $site_name = get_bloginfo( 'name' );
+ $site_name = wp_specialchars_decode( (string) get_bloginfo( 'name' ), ENT_QUOTES ); // Plain text: email subjects showed &.
$site_url = site_url();
$reply_subject = 'Re: ' . $subject;
$mailto_url = 'mailto:' . esc_attr( $email ) . '?subject=' . rawurlencode( $reply_subject );
@@ -1092,7 +1269,7 @@
<div>
<span style="display: inline-block; background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3); color: #ffffff; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-right: 6px; margin-top: 4px;">' . esc_html__( 'Status: New', 'chatbot' ) . '</span>
<span style="display: inline-block; background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3); color: #ffffff; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-right: 6px; margin-top: 4px;">' . esc_html( $date_str ) . '</span>
- <span style="display: inline-block; background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3); color: #ffffff; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-top: 4px;">' . esc_html__( 'Source: Live Chat', 'chatbot' ) . '</span>
+ <span style="display: inline-block; background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3); color: #ffffff; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-top: 4px;">' . esc_html__( 'Source: Chatbot', 'chatbot' ) . '</span>
</div>
</td>
</tr>
@@ -1183,6 +1360,48 @@
die();
}
}
+if ( ! function_exists( 'qcld_wpbot_save_email_lead' ) ) {
+ /**
+ * Save an email address a visitor typed in the chat to User Data (wpbot_subscription), once per
+ * address, and tell lead integrations (qcwpbot_chatbot_lead_captured) about a new one. Used by
+ * "Send us Email" (QA, 18 November 2026: only the greeting's "ask for email" step saved it).
+ *
+ * @param string $name Visitor name.
+ * @param string $email Email address.
+ * @param string $url Page the chat was on.
+ * @param string $user_agent Browser.
+ * @return bool Whether a new row was added.
+ */
+ function qcld_wpbot_save_email_lead( $name, $email, $url = '', $user_agent = '' ) {
+ global $wpdb;
+ $email = sanitize_email( (string) $email );
+ if ( '' === $email || ! is_email( $email ) ) {
+ return false;
+ }
+ $table = $wpdb->prefix . 'wpbot_subscription';
+ $table_sql = '`' . esc_sql( $table ) . '`';
+ $exists = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$table_sql} WHERE email = %s LIMIT 1", $email ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
+ if ( null !== $exists ) {
+ return false;
+ }
+ $row = array(
+ 'date' => current_time( 'mysql' ),
+ 'name' => sanitize_text_field( (string) $name ),
+ 'email' => $email,
+ 'phone' => '',
+ 'url' => esc_url_raw( (string) $url ),
+ 'user_agent' => sanitize_text_field( (string) $user_agent ),
+ );
+ $added = $wpdb->insert( $table, $row, array( '%s', '%s', '%s', '%s', '%s', '%s' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
+ if ( ! $added ) {
+ return false;
+ }
+ unset( $row['date'] );
+ // Same payload as qcld_wb_chatbot_email_subscription() (AI Marketing adds the contact).
+ do_action( 'qcwpbot_chatbot_lead_captured', $row );
+ return true;
+ }
+}
//Support Phone
add_action('wp_ajax_qcld_wb_chatbot_support_phone', 'qcld_wb_chatbot_support_phone');
add_action('wp_ajax_nopriv_qcld_wb_chatbot_support_phone', 'qcld_wb_chatbot_support_phone');
@@ -1198,8 +1417,13 @@
$matches = $matches[0];
if ( empty( $matches ) ) {
+ // Not a phone number: ask again (the chat keeps the phone step). It used to answer with the
+ // "could not collect your phone number" failure text (QA, 18 November 2026).
$response['status'] = 'invalid';
- $response['message'] = str_replace( '\', '', get_option( 'qlcd_wp_chatbot_phone_fail' ) );
+ $response['message'] = qcld_wpbot_valid_phone_message();
+ if ( ob_get_length() ) {
+ ob_clean();
+ }
echo wp_json_encode( $response );
} else {
$phone = $matches[0];
@@ -1235,7 +1459,7 @@
$response['status'] = 'fail';
$response['message'] = str_replace( '\', '', wp_kses_post( get_option( 'qlcd_wp_chatbot_phone_fail' ) ) );
$primary_color = '#5b4e96';
- $site_name = get_bloginfo( 'name' );
+ $site_name = wp_specialchars_decode( (string) get_bloginfo( 'name' ), ENT_QUOTES ); // Plain text: email subjects showed &.
$site_url = site_url();
$date_str = current_time( 'M j, Y - g:i a' );
$tel_url = 'tel:' . esc_attr( preg_replace( '/[^0-9+]/', '', $phone ) );
@@ -1276,7 +1500,7 @@
<div>
<span style="display: inline-block; background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3); color: #ffffff; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-right: 6px; margin-top: 4px;">' . esc_html__( 'Action Required', 'chatbot' ) . '</span>
<span style="display: inline-block; background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3); color: #ffffff; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-right: 6px; margin-top: 4px;">' . esc_html( $date_str ) . '</span>
- <span style="display: inline-block; background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3); color: #ffffff; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-top: 4px;">' . esc_html__( 'Source: Live Chat', 'chatbot' ) . '</span>
+ <span style="display: inline-block; background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3); color: #ffffff; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-top: 4px;">' . esc_html__( 'Source: Chatbot', 'chatbot' ) . '</span>
</div>
</td>
</tr>
@@ -1339,12 +1563,32 @@
$response['status'] = 'success';
$response['message'] = str_replace( '\', '', wp_kses_post( get_option( 'qlcd_wp_chatbot_phone_sent' ) ) );
}
- ob_clean();
+ if ( ob_get_length() ) {
+ ob_clean();
+ }
echo wp_json_encode( $response );
}
die();
}
}
+
+if ( ! function_exists( 'qcld_wpbot_valid_phone_message' ) ) {
+ /**
+ * The "please enter a valid phone number" message for "Leave your number": the saved text
+ * (qlcd_wp_chatbot_valid_phone_number, one text or a list) or the default.
+ *
+ * @return string
+ */
+ function qcld_wpbot_valid_phone_message() {
+ $saved = maybe_unserialize( get_option( 'qlcd_wp_chatbot_valid_phone_number', '' ) );
+ if ( is_array( $saved ) ) {
+ $saved = array_values( array_filter( $saved, 'is_string' ) );
+ $saved = $saved ? wpb_randmom_message_handle( $saved ) : '';
+ }
+ $saved = trim( str_replace( '\', '', (string) $saved ) );
+ return '' !== $saved ? wp_kses_post( $saved ) : esc_html__( 'Please provide a valid phone number', 'chatbot' );
+ }
+}
// Order Status part. removed
function wpb_randmom_message_handle($items){
@@ -2104,6 +2348,32 @@
}
add_action('wp_footer', 'qcld_wpbot_meta_tags', 100);
+if ( ! function_exists( 'qcld_wpbot_default_host_name' ) ) {
+ /**
+ * Default "Your Company or Website Name" (qlcd_wp_chatbot_host): the site title, as plain text, or
+ * "Our Website" when the site has no title.
+ *
+ * @return string
+ */
+ function qcld_wpbot_default_host_name() {
+ $name = trim( wp_specialchars_decode( (string) get_bloginfo( 'name' ), ENT_QUOTES ) );
+ return '' !== $name ? $name : 'Our Website';
+ }
+}
+
+/**
+ * One-time copy fix: the default "Your email was sent successfully.Thanks!" had no space. A saved
+ * value is changed only when it is exactly that old default.
+ *
+ * @return void
+ */
+function qcld_wpbot_migrate_email_sent_text() {
+ if ( 'Your email was sent successfully.Thanks!' === get_option( 'qlcd_wp_chatbot_email_sent' ) ) {
+ update_option( 'qlcd_wp_chatbot_email_sent', 'Your email was sent successfully. Thanks!' );
+ }
+}
+add_action( 'init', 'qcld_wpbot_migrate_email_sent_text' );
+
if ( ! function_exists( 'qcld_change_language_from_center' ) ) {
add_action( 'wp_ajax_qcld_change_language_from_center', 'qcld_change_language_from_center' );
add_action( 'wp_ajax_nopriv_qcld_change_language_from_center', 'qcld_change_language_from_center' );
@@ -2123,6 +2393,18 @@
if ( isset( $_POST['language'] ) ) {
$language = sanitize_text_field( wp_unslash( $_POST['language'] ) );
$language_array= json_decode($json_string)->$language;
+ // The company or website name is not a translation: keep the owner's, and replace a
+ // language's placeholder ("Our Website", "Notre Site Web"...) with the site title.
+ if ( is_object( $language_array ) ) {
+ $placeholders = array( '' );
+ foreach ( (array) json_decode( $json_string ) as $pack ) {
+ if ( is_object( $pack ) && isset( $pack->qlcd_wp_chatbot_host ) && is_string( $pack->qlcd_wp_chatbot_host ) ) {
+ $placeholders[] = $pack->qlcd_wp_chatbot_host;
+ }
+ }
+ $saved_host = trim( str_replace( '\', '', (string) get_option( 'qlcd_wp_chatbot_host' ) ) );
+ $language_array->qlcd_wp_chatbot_host = in_array( $saved_host, $placeholders, true ) ? qcld_wpbot_default_host_name() : $saved_host;
+ }
update_option( 'wp_chatbot_language_center_language', $language );
wp_send_json_success( array( 'message' => true, 'data' => $language_array, 'language' => $language ) );
} else {
--- a/chatbot/includes/admin/class-qcld-wpbot-ai-settings-access.php
+++ b/chatbot/includes/admin/class-qcld-wpbot-ai-settings-access.php
@@ -0,0 +1,363 @@
+<?php
+/**
+ * AI / Settings on WPBot > Permissions.
+ *
+ * Adds an "AI / Settings" section to WPBot Core's Permissions grid, so the site admin can let other
+ * roles (for example Editors) open AI / Settings ("View") and change it ("Manage settings and keys").
+ *
+ * The AI Settings screen belongs to the synced chatbot module (includes/chatbot), which allows only
+ * manage_options. Until the module reads a capability of its own, this host class lets a granted user
+ * through those checks for the screen's own requests only: while the screen is drawn, and in its save,
+ * "Test" and "Refresh models" requests (each after its nonce is checked). Everything else on the site
+ * still sees the user's real capabilities.
+ *
+ * What stays with administrators:
+ * - API keys and provider addresses (a provider address receives the key), removed from the post
+ * before the module saves it;
+ * - the Knowledge Base, What the chatbot knows, Answer cache, Error log and Chatbot data sections
+ * (their own handlers need manage_options), and the AI Wizard (it saves keys).
+ *
+ * Without WPBot Core's Permissions grid, AI / Settings stays with its Menu Access capability.
+ *
+ * @package Chatbot
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+if ( ! class_exists( 'QCLD_WPBot_AI_Settings_Access' ) ) {
+
+ /**
+ * AI / Settings access for roles chosen on the Permissions screen.
+ */
+ final class QCLD_WPBot_AI_Settings_Access {
+
+ /**
+ * Permissions grid section id (capabilities wpbot_ai_settings_view, wpbot_ai_settings_settings).
+ */
+ const SECTION = 'ai_settings';
+
+ /**
+ * The AI Settings page slug.
+ */
+ const PAGE = 'wpbot_openAi';
+
+ /**
+ * The module's save (admin-post), provider test and model refresh (AJAX) actions.
+ */
+ const SAVE_ACTION = 'qcld_wpbot_chat_ai_settings';
+ const TEST_ACTION = 'qcld_wpbot_chat_ai_test';
+ const REFRESH_ACTION = 'qcld_wpbot_chat_ai_models';
+
+ /**
+ * AI Settings sections a non-administrator may open.
+ */
+ const OPEN_SECTIONS = array( 'providers', 'answers', 'limits', 'usage' );
+
+ /**
+ * Sections a non-administrator may save.
+ */
+ const SAVE_SECTIONS = array( 'providers', 'answers', 'limits' );
+
+ /**
+ * Provider fields only an administrator may change (keys, and the address that receives them).
+ */
+ const ADMIN_FIELDS = array( 'key', 'remove', 'url', 'management_key', 'voyage_key' );
+
+ /**
+ * The user let through the module's manage_options checks for this request (0 = nobody).
+ *
+ * @var int
+ */
+ private static $user_id = 0;
+
+ /**
+ * Hook in.
+ *
+ * @return void
+ */
+ public static function init() {
+ add_filter( 'qcld_wpbot_core/permission_sections', array( __CLASS__, 'add_section' ) );
+ add_filter( 'qcld_wpbot_core/adopted_sections', array( __CLASS__, 'adopt_section' ) );
+ add_filter( 'qcld_wpbot_menu_capability_definitions', array( __CLASS__, 'menu_access_definitions' ) );
+ add_filter( 'user_has_cap', array( __CLASS__, 'filter_caps' ), 20, 4 );
+ add_action( 'admin_post_' . self::SAVE_ACTION, array( __CLASS__, 'before_save' ), 1 );
+ add_action( 'wp_ajax_' . self::TEST_ACTION, array( __CLASS__, 'before_ajax' ), 1 );
+ add_action( 'wp_ajax_' . self::REFRESH_ACTION, array( __CLASS__, 'before_ajax' ), 1 );
+ add_action( 'qcld_wpbot_chat/ai_settings_header', array( __CLASS__, 'limited_notice' ), 20 );
+ add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue' ), 20 );
+ }
+
+ /**
+ * Whether WPBot Core's Permissions grid is available.
+ *
+ * @return bool
+ */
+ public static function grid_available() {
+ return class_exists( 'QuantumCloudWPBotCorePermissionsSections' );
+ }
+
+ /**
+ * Capability for a level of the AI / Settings section.
+ *
+ * @param string $level view or settings.
+ * @return string
+ */
+ public static function cap( $level ) {
+ if ( ! self::grid_available() ) {
+ return 'manage_options';
+ }
+ return QuantumCloudWPBotCorePermissionsSections::cap( self::SECTION, $level );
+ }
+
+ /**
+ * Capability of the AI / Settings menu item.
+ *
+ * @return string
+ */
+ public static function menu_capability() {
+ if ( self::grid_available() ) {
+ return self::cap( 'view' );
+ }
+ return function_exists( 'qcld_wpbot_get_menu_capability' ) ? qcld_wpbot_get_menu_capability( 'wpbot_openAi' ) : 'manage_options';
+ }
+
+ /**
+ * Add the section to the Permissions screen.
+ *
+ * @param array $sections Sections.
+ * @return array
+ */
+ public static function add_section( $sections ) {
+ $sections[ self::SECTION ] = array(
+ 'label' => __( 'AI / Settings', 'chatbot' ),
+ 'description' => __( 'Which AI answers the chatbot, how it answers, spending and limits. API keys and provider addresses stay with administrators.', 'chatbot' ),
+ );
+ return $sections;
+ }
+
+ /**
+ * The old Menu Access screen no longer sets who opens AI / Settings when Permissions does.
+ *
+ * @param array $definitions Menu Access rows.
+ * @return array
+ */
+ public static function menu_access_definitions( $definitions ) {
+ if ( self::grid_available() ) {
+ unset( $definitions['wpbot_openAi'] );
+ }
+ return $definitions;
+ }
+
+ /**
+ * Switch the section to the grid.
+ *
+ * @param string[] $ids Section ids.
+ * @return string[]
+ */
+ public static function adopt_section( $ids ) {
+ $ids = (array) $ids;
+ $ids[] = self::SECTION;
+ return $ids;
+ }
+
+ /**
+ * Whether the current user opens AI / Settings through the Permissions grid (not as an administrator).
+ *
+ * @return bool
+ */
+ public static function is_limited_user() {
+ return self::grid_available() && ! current_user_can( 'manage_options' ) && current_user_can( self::cap( 'view' ) );
+ }
+
+ /**
+ * Whether the current limited user may save AI / Settings.
+ *
+ * @return bool
+ */
+ public static function can_save() {
+ return current_user_can( self::cap( 'settings' ) );
+ }
+
+ /**
+ * The requested AI Settings section ('' = the first one, Providers).
+ *
+ * @return string
+ */
+ public static function requested_section() {
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- A tab.
+ return isset( $_GET['section'] ) ? sanitize_key( wp_unslash( $_GET['section'] ) ) : '';
+ }
+
+ /**
+ * On loading AI Settings: send a limited user away from the administrators' sections.
+ *
+ * @return void
+ */
+ public static function load_page() {
+ if ( ! self::is_limited_user() ) {
+ return;
+ }
+ $section = self::requested_section();
+ $section = 'spending' === $section ? 'limits' : $section;
+ if ( '' !== $section && ! in_array( $section, self::OPEN_SECTIONS, true ) ) {
+ wp_safe_redirect( add_query_arg( array( 'page' => self::PAGE, 'section' => 'providers' ), admin_url( 'admin.php' ) ) ); // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
+ exit;
+ }
+ }
+
+ /**
+ * Draw the AI Settings screen; a limited user passes the module's manage_options check
+ * only while it is drawn.
+ *
+ * @param callable $render Draws the screen.
+ * @return void
+ */
+ public static function render( $render ) {
+ if ( ! self::is_limited_user() ) {
+ call_user_func( $render );
+ return;
+ }
+ self::$user_id = get_current_user_id();
+ try {
+ call_user_func( $render );
+ } finally {
+ self::$user_id = 0;
+ }
+ }
+
+ /**
+ * Let the chosen user through manage_options checks.
+ *
+ * @param array $allcaps All capabilities of the user.
+ * @param string[] $caps Required primitive capabilities.
+ * @param array $args Requested capability and arguments.
+ * @param WP_User $user User.
+ * @return array
+ */
+ public static function filter_caps( $allcaps, $caps, $args, $user ) {
+ if ( 0 !== self::$user_id && $user instanceof WP_User && (int) $user->ID === self::$user_id && in_array( 'manage_options', (array) $caps, true ) ) {
+ $allcaps['manage_options'] = true;
+ }
+ return $allcaps;
+ }
+
+ /**
+ * Before the module saves AI Settings: check a limited user's nonce and level, keep the
+ * administrators' fields out, then let the save through.
+ *
+ * @return void
+ */
+ public static function before_save() {
+ if ( ! self::is_limited_user() ) {
+ return;
+ }
+ if ( ! self::can_save() ) {
+ wp_die( esc_html__( 'You can view AI / Settings but not change it.', 'chatbot' ), 403 );
+ }
+ check_admin_referer( self::SAVE_ACTION );
+ $section = isset( $_POST['section'] ) ? sanitize_key( wp_unslash( $_POST['section'] ) ) : 'providers';
+ if ( ! in_array( $section, self::SAVE_SECTIONS, true ) ) {
+ wp_die( esc_html__( 'Only an administrator can change this part of AI / Settings.', 'chatbot' ), 403 );
+ }
+ // Only removing fields: the post stays slashed for the module, which unslashes and sanitizes what is left.
+ if ( isset( $_POST['providers'] ) && is_array( $_POST['providers'] ) ) {
+ $_POST['providers'] = self::strip_admin_fields( $_POST['providers'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
+ }
+ // The module's save redirects and exits; nothing after it runs in this requ