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 / general.php

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

228 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * General Tab - Account Connection
4 */
5
6 if (!defined('ABSPATH')) {
7 exit;
8 }
9
10 function onwebchat_general_tab($isConnected = false) {
11
12 // Note: Form submissions are handled in admin_init hook (see onwebchat.php)
13 // This ensures redirects happen before any WordPress admin output
14
15 $options = get_option('onwebchat_plugin_option');
16 $chatId = isset($options['text_string']) ? $options['text_string'] : '';
17
18 ?>
19
20 <?php if (!$isConnected): ?>
21 <!-- Not Connected - Show Login Form -->
22 <h2>Connect Your Account</h2>
23 <p>Link your WordPress site to your onWebChat account to enable the live chat widget and AI features.</p>
24
25 <form action="admin.php?page=onwebchat_settings&tab=general" method="post">
26 <input type="hidden" name="action" value="login">
27 <?php wp_nonce_field('on_web_chat_nonce'); ?>
28
29 <!-- Option 1: Email/Password Login -->
30 <div class="card" style="max-width: 600px; margin: 20px 0; padding: 20px; background: #fff; border: 1px solid #c3c4c7; box-shadow: 0 1px 1px rgba(0,0,0,.04);">
31 <h3 style="margin-top: 0; display: flex; align-items: center; gap: 8px;">
32 <span style="background: #2271b1; color: #fff; width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 14px;">1</span>
33 Login with your onWebChat Email & Password
34 </h3>
35 <p style="color: #646970; margin-bottom: 15px;">
36 Recommended enables automatic WooCommerce sync connection.
37 </p>
38
39 <table class="form-table" style="margin: 0;">
40 <tr>
41 <th scope="row" style="width: 100px; padding: 10px 10px 10px 0;">
42 <label for="onWebChatUser">onWebChat Email (username)</label>
43 </th>
44 <td style="padding: 10px 0;">
45 <input type="email"
46 id="onWebChatUser"
47 name="onWebChatUser"
48 class="regular-text"
49 placeholder="Your registered email"
50 value="<?php echo esc_attr(get_option('onwebchat_plugin_option_user')); ?>">
51 </td>
52 </tr>
53 <tr>
54 <th scope="row" style="width: 100px; padding: 10px 10px 10px 0;">
55 <label for="onWebChatPass">onWebChat Password</label>
56 </th>
57 <td style="padding: 10px 0;">
58 <input type="password"
59 id="onWebChatPass"
60 name="onWebChatPass"
61 class="regular-text"
62 placeholder="Your account password">
63 </td>
64 </tr>
65 </table>
66 </div>
67
68 <!-- Divider -->
69 <div style="max-width: 600px; display: flex; align-items: center; margin: 25px 0;">
70 <div style="flex: 1; height: 1px; background: #c3c4c7;"></div>
71 <span style="padding: 0 20px; color: #646970; font-size: 14px; font-weight: 500;">OR</span>
72 <div style="flex: 1; height: 1px; background: #c3c4c7;"></div>
73 </div>
74
75 <!-- Option 2: Chat ID -->
76 <div class="card" style="max-width: 600px; margin: 20px 0; padding: 20px; background: #fff; border: 1px solid #c3c4c7; box-shadow: 0 1px 1px rgba(0,0,0,.04);">
77 <h3 style="margin-top: 0; display: flex; align-items: center; gap: 8px;">
78 <span style="background: #646970; color: #fff; width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 14px;">2</span>
79 Use Chat ID Only
80 </h3>
81 <p style="color: #646970; margin-bottom: 15px;">
82 Quick setup paste your Chat ID from your onWebChat dashboard.
83 </p>
84
85 <table class="form-table" style="margin: 0;">
86 <tr>
87 <th scope="row" style="width: 100px; padding: 10px 10px 10px 0;">
88 <label for="chatId">Chat ID</label>
89 </th>
90 <td style="padding: 10px 0;">
91 <input type="text"
92 id="chatId"
93 name="chatId"
94 class="regular-text"
95 placeholder="e.g. 3a02c87b60726a4663b25463a424a248"
96 value="<?php echo esc_attr($chatId); ?>">
97 <p class="description">Found in your onWebChat Dashboard → Settings -> Widget → Installation</p>
98 </td>
99 </tr>
100 </table>
101 </div>
102
103 <!-- Submit Button -->
104 <p style="margin-top: 20px;">
105 <button type="submit" class="button button-primary button-hero">
106 Connect Account
107 </button>
108 </p>
109
110 <!-- New Account Link -->
111 <p style="margin-top: 15px; color: #646970;">
112 Don't have an onWebChat account yet?
113 <a href="https://www.onwebchat.com/signup.php" target="_blank">Create one here</a> to get started.
114 </p>
115 </form>
116
117 <?php else: ?>
118 <!-- Connected Status -->
119 <h2>Account Connected</h2>
120
121 <p style="color: #646970; margin: 10px 0 20px 0;">
122 <?php
123 $userOption = get_option('onwebchat_plugin_option_user');
124 if (!empty($userOption)) {
125 echo '<span style="color: #2271b1;"></span> <strong>Connected as:</strong> ' . esc_html($userOption);
126 } else {
127 $chatIdOption = get_option('onwebchat_plugin_option');
128 $displayChatId = isset($chatIdOption['text_string']) ? $chatIdOption['text_string'] : '';
129 echo '<span style="color: #2271b1;"></span> <strong>Connected with Chat ID:</strong> <code>' . esc_html($displayChatId) . '</code>';
130 }
131 ?>
132 </p>
133
134 <div class="card" style="max-width: 600px; margin: 20px 0; padding: 20px; background: #fff; border: 1px solid #c3c4c7; box-shadow: 0 1px 1px rgba(0,0,0,.04);">
135 <h3 style="margin-top: 0;">Quick Actions</h3>
136
137 <p>
138 <a href="https://www.onwebchat.com/login.php" target="_blank" class="button button-secondary">
139 Open onWebChat Dashboard →
140 </a>
141 </p>
142
143 <hr style="margin: 20px 0; border: none; border-top: 1px solid #c3c4c7;">
144
145 <p style="margin-bottom: 0;">
146 <a href="admin.php?page=onwebchat_settings&tab=general&action=deactivate"
147 style="color: #b32d2e; text-decoration: none;"
148 onclick="return confirm('Are you sure you want to unlink your account? The chat widget will be removed from your site.');">
149 Unlink Account
150 </a>
151 <span style="color: #646970; margin-left: 5px;">— Disconnect this WordPress site from onWebChat</span>
152 </p>
153 </div>
154
155 <?php endif; ?>
156 <?php
157 }
158
159 /**
160 * Handle form submissions for general tab
161 */
162 function onwebchat_handle_general_actions() {
163
164 // Handle login/connection
165 if (isset($_POST["action"]) && $_POST["action"] == "login") {
166
167 if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'on_web_chat_nonce')) {
168 wp_die('Sorry, your nonce did not verify.');
169 }
170
171 // Same rule as the WooCommerce tab: the password is only forwarded to onWebChat, so it
172 // must be un-slashed and NOT sanitized, otherwise sanitize_text_field() silently strips
173 // characters (spaces, %xx sequences, "<") and the correct password is refused.
174 $userName = isset($_POST["onWebChatUser"]) ? sanitize_text_field(wp_unslash($_POST["onWebChatUser"])) : '';
175 $userPass = isset($_POST["onWebChatPass"]) ? (string) wp_unslash($_POST["onWebChatPass"]) : '';
176 $chatId = isset($_POST["chatId"]) ? sanitize_text_field(wp_unslash($_POST["chatId"])) : '';
177
178 if (isChatIdValid($chatId)) {
179 // Direct Chat ID provided
180 $my_options = get_option('onwebchat_plugin_option');
181 $my_options['text_string'] = $chatId;
182 update_option('onwebchat_plugin_option', $my_options);
183 update_option('onwebchat_plugin_option_user', '');
184 update_option('onwebchat_plugin_option_pages_select', 1);
185
186 wp_redirect(admin_url('admin.php?page=onwebchat_settings&tab=general'));
187 exit;
188
189 } else {
190 // Try to get Chat ID from server
191 update_option('onwebchat_plugin_option_user', $userName);
192
193 $response = wp_remote_post(ONWEBCHAT_SERVER_URL, array(
194 'method' => 'POST',
195 'timeout' => 45,
196 'body' => array('email' => $userName, 'pass' => $userPass),
197 ));
198
199 if (!is_wp_error($response) && !empty($response['body'])) {
200 $my_options = get_option('onwebchat_plugin_option');
201 $my_options['text_string'] = $response['body'];
202 update_option('onwebchat_plugin_option', $my_options);
203 update_option('onwebchat_plugin_option_pages_select', 1);
204
205 // Also fetch WooCommerce secret with same credentials
206 // This way user doesn't need to re-enter credentials in WooCommerce tab
207 onwebchat_fetch_wc_secret_on_login($userName, $userPass, $response['body']);
208
209 wp_redirect(admin_url('admin.php?page=onwebchat_settings&tab=general'));
210 exit;
211 } else {
212 onwebchat_login_error(true);
213 }
214 }
215 }
216
217 // Handle disconnect
218 if (isset($_GET["action"]) && $_GET["action"] == "deactivate") {
219 $my_options = get_option('onwebchat_plugin_option');
220 $my_options['text_string'] = '';
221 update_option('onwebchat_plugin_option', $my_options);
222 update_option('onwebchat_plugin_option_pages_select', 1);
223
224 wp_redirect(admin_url('admin.php?page=onwebchat_settings&tab=general'));
225 exit;
226 }
227 }
228