PluginProbe
Live Chat & AI Chatbot – onWebChat / 3.9.3
Live Chat & AI Chatbot – onWebChat v3.9.3
3.9.2 3.9.3 3.9.1 3.9.0 3.8.4 3.8.2 3.8.1 3.8.0 3.7.2 3.7.1 3.7.0 3.6.0 3.5.5 trunk 1.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 All 48 releases
onwebchat / admin / tabs / chat.php

chat.php in Live Chat & AI Chatbot – onWebChat 3.9.3, at admin/tabs/chat.php

161 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Chat Widget Tab - Display & Visibility Settings
4 */
5
6 if (!defined('ABSPATH')) {
7 exit;
8 }
9
10 function onwebchat_chat_tab() {
11
12 // Handle form submissions
13 onwebchat_handle_chat_actions();
14
15 $options = get_option('onwebchat_plugin_option');
16 $chatId = isset($options['text_string']) ? $options['text_string'] : '';
17 $pagesSelect = get_option('onwebchat_plugin_option_pages_select', 1);
18
19 ?>
20 <form action="admin.php?page=onwebchat_settings&tab=chat" method="post">
21 <input type="hidden" name="action" value="save_chat_settings">
22 <input type="hidden" name="chatId" value="<?php echo esc_attr($chatId); ?>">
23 <?php wp_nonce_field('on_web_chat_nonce'); ?>
24
25 <h2>Chat Widget Visibility</h2>
26 <p>Control where the chat widget appears on your website.</p>
27
28 <table class="form-table">
29 <tr>
30 <th scope="row">
31 <label for="pages-select">Display Options</label>
32 </th>
33 <td>
34 <select id="pages-select" name="pages-select" onchange="onwc_select_change()" style="width: 400px;">
35 <option value="1" <?php selected($pagesSelect, 1); ?>>
36 Show the chat widget on all pages
37 </option>
38 <option value="2" <?php selected($pagesSelect, 2); ?>>
39 Show the chat widget only on selected pages
40 </option>
41 <option value="3" <?php selected($pagesSelect, 3); ?>>
42 Hide the chat widget on selected pages
43 </option>
44 <option value="4" <?php selected($pagesSelect, 4); ?>>
45 Hide the chat widget on all pages
46 </option>
47 </select>
48 </td>
49 </tr>
50
51 <tr id="onwc_show_on_pages_row" style="display:none;">
52 <th scope="row">
53 <label for="showonpages">Show Only On</label>
54 </th>
55 <td>
56 <input id="showonpages" name="showonpages" type="text" class="regular-text"
57 value="<?php echo esc_attr(get_option('onwebchat_plugin_option_show_pages')); ?>" />
58 <p class="description">
59 Add multiple pages by separating them with a space. You can enter a full URL or just part of it.<br>
60 Example: <code>index price contact.php blog/</code>
61 </p>
62 </td>
63 </tr>
64
65 <tr id="onwc_hide_on_pages_row" style="display:none;">
66 <th scope="row">
67 <label for="hideonpages">Hide On</label>
68 </th>
69 <td>
70 <input id="hideonpages" name="hideonpages" type="text" class="regular-text"
71 value="<?php echo esc_attr(get_option('onwebchat_plugin_option_hide_pages')); ?>" />
72 <p class="description">
73 Add multiple pages by separating them with a space. You can enter a full URL or just part of it.<br>
74 Example: <code>index price contact.php blog/</code>
75 </p>
76 </td>
77 </tr>
78
79 <tr>
80 <th scope="row">
81 <label for="logged-only">Signed-in Users Only</label>
82 </th>
83 <td>
84 <label>
85 <input id="logged-only" name="logged-only" type="checkbox" value="1"
86 <?php checked(get_option('onwebchat_plugin_option_logged_only', 0), 1); ?> />
87 Show the chat widget only to signed-in (logged-in) users
88 </label>
89 <p class="description">
90 When enabled, visitors who are not logged in to your website will not see the chat widget at all.
91 </p>
92 </td>
93 </tr>
94 </table>
95
96 <p class="submit">
97 <input type="submit" class="button button-primary" value="Save Chat Settings">
98 </p>
99 </form>
100
101 <script type="text/javascript">
102 function onwc_select_change() {
103 var e = document.getElementById("pages-select");
104 if (!e) return;
105
106 var selected = e.options[e.selectedIndex].value;
107 var showRow = document.getElementById("onwc_show_on_pages_row");
108 var hideRow = document.getElementById("onwc_hide_on_pages_row");
109
110 showRow.style.display = "none";
111 hideRow.style.display = "none";
112
113 if (selected == 2) {
114 showRow.style.display = "table-row";
115 } else if (selected == 3) {
116 hideRow.style.display = "table-row";
117 }
118 }
119
120 // Run on page load
121 document.addEventListener('DOMContentLoaded', function() {
122 onwc_select_change();
123 });
124 </script>
125 <?php
126 }
127
128 /**
129 * Handle form submissions for chat tab
130 */
131 function onwebchat_handle_chat_actions() {
132
133 if (isset($_POST["action"]) && $_POST["action"] == "save_chat_settings") {
134
135 if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'on_web_chat_nonce')) {
136 wp_die('Sorry, your nonce did not verify.');
137 }
138
139 if (!current_user_can('manage_options')) {
140 wp_die('Insufficient permissions.');
141 }
142
143 $pagesSelect = isset($_POST["pages-select"]) ? absint($_POST["pages-select"]) : 1;
144 $showOnPages = isset($_POST["showonpages"]) ? sanitize_text_field($_POST["showonpages"]) : '';
145 $hideOnPages = isset($_POST["hideonpages"]) ? sanitize_text_field($_POST["hideonpages"]) : '';
146 $loggedOnly = isset($_POST["logged-only"]) ? 1 : 0; // unchecked checkboxes are not posted (default: off)
147
148 update_option('onwebchat_plugin_option_pages_select', $pagesSelect);
149 update_option('onwebchat_plugin_option_logged_only', $loggedOnly);
150
151 if ($pagesSelect == 2) {
152 update_option('onwebchat_plugin_option_show_pages', $showOnPages);
153 } else if ($pagesSelect == 3) {
154 update_option('onwebchat_plugin_option_hide_pages', $hideOnPages);
155 }
156
157 echo '<div class="notice notice-success"><p>Chat settings saved successfully!</p></div>';
158 }
159 }
160
161