| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: Boei – AI Chatbot, Live Chat & 50+ Channels |
| 4 |
* Version: 1.9.3 |
| 5 |
* Plugin URI: https://boei.help/ai-chatbot/wordpress/?utm_source=wp_plugin&utm_medium=plugin_admin&utm_campaign=plugin_header |
| 6 |
* Description: Capture every lead. Reply instantly. Close more deals. AI chatbot, 50+ contact channels, single inbox, and lead tracking—all in one plugin. |
| 7 |
* Author: Boei |
| 8 |
* Author URI: https://www.boei.help/?utm_source=wp_plugin&utm_medium=plugin_admin&utm_campaign=author_header |
| 9 |
* Tested up to: 7.0 |
| 10 |
* Requires at least: 5.0 |
| 11 |
* License: GPL v2 or later |
| 12 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 13 |
* Text Domain: boei-help |
| 14 |
* Domain Path: /languages |
| 15 |
* |
| 16 |
* @package Boei |
| 17 |
* @author Boei |
| 18 |
* @license GPL-2.0-or-later |
| 19 |
*/ |
| 20 |
|
| 21 |
if (!defined('ABSPATH')) { |
| 22 |
exit; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Return allowed HTML tag list for inline SVG icons rendered in the admin UI. |
| 27 |
* |
| 28 |
* Used with wp_kses() so the plugin can safely echo static SVG markup while |
| 29 |
* still passing the WP.org Plugin Check output-escaping rules. |
| 30 |
*/ |
| 31 |
function boei_allowed_svg_tags() |
| 32 |
{ |
| 33 |
return array( |
| 34 |
'svg' => array( |
| 35 |
'width' => true, 'height' => true, 'viewbox' => true, 'fill' => true, |
| 36 |
'xmlns' => true, 'stroke' => true, 'stroke-width' => true, |
| 37 |
), |
| 38 |
'path' => array( |
| 39 |
'd' => true, 'fill' => true, 'stroke' => true, |
| 40 |
'stroke-linecap' => true, 'stroke-linejoin' => true, 'stroke-width' => true, |
| 41 |
), |
| 42 |
'circle' => array('cx' => true, 'cy' => true, 'r' => true, 'fill' => true), |
| 43 |
'g' => array('fill' => true, 'stroke' => true), |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Verify widget key with Boei API |
| 49 |
* |
| 50 |
* @param string $key The widget key to verify |
| 51 |
* @return bool True if valid, false otherwise |
| 52 |
*/ |
| 53 |
function boei_verify_key($key) |
| 54 |
{ |
| 55 |
if (empty($key)) { |
| 56 |
return false; |
| 57 |
} |
| 58 |
|
| 59 |
$response = wp_remote_get( |
| 60 |
'https://app.boei.help/api/domains/' . sanitize_text_field($key) . '/verify', |
| 61 |
array( |
| 62 |
'timeout' => 10, |
| 63 |
'headers' => array( |
| 64 |
'Accept' => 'application/json', |
| 65 |
), |
| 66 |
) |
| 67 |
); |
| 68 |
|
| 69 |
if (is_wp_error($response)) { |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
$body = wp_remote_retrieve_body($response); |
| 74 |
$data = json_decode($body, true); |
| 75 |
|
| 76 |
return isset($data['valid']) && $data['valid'] === true; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* AJAX handler for widget key verification |
| 81 |
*/ |
| 82 |
function boei_ajax_verify_key() |
| 83 |
{ |
| 84 |
check_ajax_referer('boei_verify_key', 'nonce'); |
| 85 |
|
| 86 |
if (!current_user_can('manage_options')) { |
| 87 |
wp_send_json_error(array('message' => __('Unauthorized', 'boei-help'))); |
| 88 |
} |
| 89 |
|
| 90 |
$key = isset($_POST['key']) ? sanitize_text_field(wp_unslash($_POST['key'])) : ''; |
| 91 |
|
| 92 |
if (empty($key)) { |
| 93 |
wp_send_json_error(array('message' => __('Please enter a widget key', 'boei-help'))); |
| 94 |
} |
| 95 |
|
| 96 |
$is_valid = boei_verify_key($key); |
| 97 |
|
| 98 |
if ($is_valid) { |
| 99 |
wp_send_json_success(array('message' => __('Widget key is valid!', 'boei-help'))); |
| 100 |
} else { |
| 101 |
wp_send_json_error(array('message' => __('Invalid widget key. Please check and try again.', 'boei-help'))); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
add_action('wp_ajax_boei_verify_key', 'boei_ajax_verify_key'); |
| 106 |
|
| 107 |
/** |
| 108 |
* Validate widget key before saving |
| 109 |
* |
| 110 |
* @param string $value The value to sanitize |
| 111 |
* @return string The sanitized value, or previous value if invalid |
| 112 |
*/ |
| 113 |
function boei_sanitize_key($value) |
| 114 |
{ |
| 115 |
$value = sanitize_text_field($value); |
| 116 |
$previous_value = get_option('boei_key_option', ''); |
| 117 |
|
| 118 |
// If empty, show error |
| 119 |
if (empty($value)) { |
| 120 |
add_settings_error( |
| 121 |
'boei_key_option', |
| 122 |
'empty_key', |
| 123 |
__('Please enter a widget key', 'boei-help'), |
| 124 |
'error' |
| 125 |
); |
| 126 |
return ''; |
| 127 |
} |
| 128 |
|
| 129 |
// Verify the key with the API |
| 130 |
if (!boei_verify_key($value)) { |
| 131 |
add_settings_error( |
| 132 |
'boei_key_option', |
| 133 |
'invalid_key', |
| 134 |
__('Invalid widget key. Please check and try again.', 'boei-help'), |
| 135 |
'error' |
| 136 |
); |
| 137 |
// Return the previous value so invalid keys don't get saved |
| 138 |
return $previous_value; |
| 139 |
} |
| 140 |
|
| 141 |
// If this is a first-time connection, set celebration flag |
| 142 |
if (empty($previous_value) && !empty($value)) { |
| 143 |
set_transient('boei_just_connected', true, 30); |
| 144 |
} |
| 145 |
|
| 146 |
return $value; |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Optional function for users that want to test on localhost with their live domain |
| 151 |
* |
| 152 |
* @link https://app.boei.help/docs/1.0/localhost |
| 153 |
* Not used anymore for loading the script for Telegram, Twitter DMs, etc |
| 154 |
* Now use the advanced installation method. |
| 155 |
*/ |
| 156 |
// function boei_localhost_test(){ |
| 157 |
// echo '<script>window.Boei_Test_Hostname = "example.com";</script>'; |
| 158 |
// } |
| 159 |
// add_action('wp_head', 'boei_localhost_test'); |
| 160 |
|
| 161 |
/** |
| 162 |
* Loading the Boei script on the frontend. |
| 163 |
* wp_enqueue_script() function doesn’t support async. |
| 164 |
* This will load the script for Telegram, Twitter DMs, SMS, WeChat, etc |
| 165 |
*/ |
| 166 |
function boei_load_script() |
| 167 |
{ |
| 168 |
if (boei_get_key()) { |
| 169 |
// Advanced installation |
| 170 |
wp_enqueue_script('boei', 'https://app.boei.help/embed/k/' . boei_get_key(), array(), '1.0', true); |
| 171 |
} else { |
| 172 |
// Regular installation |
| 173 |
wp_enqueue_script('boei', 'https://cdn.boei.help/hello.js', array(), '1.0', true); |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
add_action('wp_enqueue_scripts', 'boei_load_script'); |
| 178 |
|
| 179 |
/** |
| 180 |
* Adding link to the Boei settings page in wp-plugins admin |
| 181 |
* On the settings page, one can manage the buttons with Telegram, Twitter DMs, SMS, WeChat, etc |
| 182 |
*/ |
| 183 |
function boei_admin_action_links($links) |
| 184 |
{ |
| 185 |
$links = array_merge(array( |
| 186 |
'<a href="' . esc_url(add_query_arg( |
| 187 |
'page', |
| 188 |
'boei-help-settings', |
| 189 |
get_admin_url() . 'admin.php' |
| 190 |
)) . '">' . __('Setup & Settings', 'boei-help') . '</a>', |
| 191 |
'<a href="' . esc_url(boei_url_homepage()) . '">' . __('Support', 'boei-help') . '</a>', |
| 192 |
), $links); |
| 193 |
|
| 194 |
return $links; |
| 195 |
} |
| 196 |
|
| 197 |
add_action('plugin_action_links_' . plugin_basename(__FILE__), 'boei_admin_action_links'); |
| 198 |
|
| 199 |
/** |
| 200 |
* Add menu option for Boei and register the settings |
| 201 |
* Clicking on it will lead to the settings for Telegram, Twitter DMs, etc |
| 202 |
*/ |
| 203 |
function boei_register_admin() |
| 204 |
{ |
| 205 |
// Add top-level menu with chat icon |
| 206 |
add_menu_page(__('Boei', 'boei-help'), __('Boei', 'boei-help'), 'manage_options', 'boei-help-settings', 'boei_settings', 'dashicons-format-chat'); |
| 207 |
|
| 208 |
// Register the settings with sanitize callback |
| 209 |
register_setting( |
| 210 |
'boei_key', |
| 211 |
'boei_key_option', |
| 212 |
array( |
| 213 |
'type' => 'string', |
| 214 |
'sanitize_callback' => 'boei_sanitize_key', |
| 215 |
) |
| 216 |
); |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
add_action('admin_menu', 'boei_register_admin'); |
| 221 |
|
| 222 |
/** |
| 223 |
* Return value of the Boei key |
| 224 |
* The advanced installation key for the script for Telegram, Twitter DMs, etc |
| 225 |
*/ |
| 226 |
function boei_get_key() |
| 227 |
{ |
| 228 |
return get_option('boei_key_option'); |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* Display settings and installation page |
| 233 |
* This basically redirects to the Boei admin area. |
| 234 |
* On the admin area, one can manage the buttons and helpers for Telegram, Twitter DMs, etc |
| 235 |
*/ |
| 236 |
function boei_settings() |
| 237 |
{ |
| 238 |
// URLs are escaped at each echo point below (esc_url()) rather than |
| 239 |
// pre-escaped here, so the WP.org Plugin Check output-escaping rule |
| 240 |
// detects escaping at the actual output boundary. |
| 241 |
$homepageURL = boei_url_homepage(); |
| 242 |
$installationURL = 'https://boei.help/docs/installation-wordpress?utm_source=wp_plugin&utm_medium=plugin_admin&utm_campaign=onboarding_docs'; |
| 243 |
$roadmapURL = 'https://feedback.boei.help?utm_source=wp_plugin&utm_medium=plugin_admin&utm_campaign=footer_roadmap'; |
| 244 |
|
| 245 |
$current_user = wp_get_current_user(); |
| 246 |
$boei_register_email = $current_user->user_email; |
| 247 |
$urlparts = wp_parse_url(home_url()); |
| 248 |
$boei_register_domain = !empty($urlparts['host']) ? $urlparts['host'] : ''; |
| 249 |
$registerURL = 'https://app.boei.help/register?utm_source=wp_plugin&utm_medium=plugin_admin&utm_campaign=onboarding_register&email=' . urlencode($boei_register_email) . '&domain=' . urlencode($boei_register_domain); |
| 250 |
|
| 251 |
$has_key = !empty(boei_get_key()); |
| 252 |
|
| 253 |
echo '<div class="wrap">'; |
| 254 |
echo '<h1 style="display: flex; align-items: center; gap: 10px; margin-bottom: 20px;">'; |
| 255 |
echo '<svg width="32" height="32" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="50" fill="#713eec"/><path d="M30 35c0-2.8 2.2-5 5-5h30c2.8 0 5 2.2 5 5v20c0 2.8-2.2 5-5 5H45l-10 10v-10h-5c-2.8 0-5-2.2-5-5V35z" fill="#fff"/></svg>'; |
| 256 |
echo 'Boei</h1>'; |
| 257 |
|
| 258 |
// Add inline CSS for hover effects and JS for key verification |
| 259 |
echo '<style>.boei-card:hover { border-color: #713eec !important; }</style>'; |
| 260 |
?> |
| 261 |
<script> |
| 262 |
function boeiTestKey() { |
| 263 |
var keyInput = document.querySelector('#boei-key-edit input[name="boei_key_option"], input[name="boei_key_option"]'); |
| 264 |
var testBtn = document.getElementById('boei-test-btn'); |
| 265 |
var resultSpan = document.getElementById('boei-test-result'); |
| 266 |
var key = keyInput ? keyInput.value.trim() : ''; |
| 267 |
|
| 268 |
if (!key) { |
| 269 |
resultSpan.innerHTML = '<span style="color: #d63638;"><?php echo esc_js(__('Please enter a widget key', 'boei-help')); ?></span>'; |
| 270 |
return; |
| 271 |
} |
| 272 |
|
| 273 |
testBtn.disabled = true; |
| 274 |
testBtn.textContent = '<?php echo esc_js(__('Testing...', 'boei-help')); ?>'; |
| 275 |
resultSpan.innerHTML = ''; |
| 276 |
|
| 277 |
var formData = new FormData(); |
| 278 |
formData.append('action', 'boei_verify_key'); |
| 279 |
formData.append('nonce', '<?php echo esc_attr(wp_create_nonce('boei_verify_key')); ?>'); |
| 280 |
formData.append('key', key); |
| 281 |
|
| 282 |
fetch(ajaxurl, { |
| 283 |
method: 'POST', |
| 284 |
body: formData |
| 285 |
}) |
| 286 |
.then(function(response) { return response.json(); }) |
| 287 |
.then(function(data) { |
| 288 |
testBtn.disabled = false; |
| 289 |
testBtn.textContent = '<?php echo esc_js(__('Test', 'boei-help')); ?>'; |
| 290 |
if (data.success) { |
| 291 |
resultSpan.innerHTML = '<span style="color: #00a32a;">✓ ' + data.data.message + '</span>'; |
| 292 |
} else { |
| 293 |
resultSpan.innerHTML = '<span style="color: #d63638;">✗ ' + data.data.message + '</span>'; |
| 294 |
} |
| 295 |
}) |
| 296 |
.catch(function() { |
| 297 |
testBtn.disabled = false; |
| 298 |
testBtn.textContent = '<?php echo esc_js(__('Test', 'boei-help')); ?>'; |
| 299 |
resultSpan.innerHTML = '<span style="color: #d63638;"><?php echo esc_js(__('Connection error. Please try again.', 'boei-help')); ?></span>'; |
| 300 |
}); |
| 301 |
} |
| 302 |
|
| 303 |
function boeiShowEdit() { |
| 304 |
document.getElementById('boei-key-display').style.display = 'none'; |
| 305 |
document.getElementById('boei-key-edit').style.display = 'block'; |
| 306 |
} |
| 307 |
|
| 308 |
function boeiCancelEdit() { |
| 309 |
document.getElementById('boei-key-edit').style.display = 'none'; |
| 310 |
document.getElementById('boei-key-display').style.display = 'flex'; |
| 311 |
document.getElementById('boei-test-result').innerHTML = ''; |
| 312 |
} |
| 313 |
|
| 314 |
function boeiDeactivate() { |
| 315 |
if (confirm('<?php echo esc_js(__('Are you sure you want to deactivate your widget?', 'boei-help')); ?>')) { |
| 316 |
document.getElementById('boei-deactivate-form').submit(); |
| 317 |
} |
| 318 |
} |
| 319 |
</script> |
| 320 |
<?php |
| 321 |
settings_errors('boei_key_option'); |
| 322 |
|
| 323 |
if ($has_key) { |
| 324 |
// ========== CONNECTED STATE ========== |
| 325 |
$just_connected = get_transient('boei_just_connected'); |
| 326 |
if ($just_connected) { |
| 327 |
delete_transient('boei_just_connected'); |
| 328 |
// Celebration message for first-time connection |
| 329 |
echo '<div style="background: linear-gradient(135deg, #713eec 0%, #9b6df5 100%); border-radius: 8px; padding: 24px; margin-bottom: 20px; color: #fff; text-align: center;">'; |
| 330 |
echo '<div style="font-size: 32px; margin-bottom: 8px;">🎉</div>'; |
| 331 |
echo '<div style="font-size: 20px; font-weight: 600; margin-bottom: 8px;">' . esc_html__("You're all set!", 'boei-help') . '</div>'; |
| 332 |
echo '<div style="opacity: 0.9;">' . esc_html__('Your Boei widget is now live on your website. Start capturing leads!', 'boei-help') . '</div>'; |
| 333 |
echo '</div>'; |
| 334 |
} else { |
| 335 |
// Regular connected message |
| 336 |
echo '<div class="notice notice-success" style="margin-bottom: 20px; padding: 12px 16px;">'; |
| 337 |
echo '<strong>' . esc_html__('Connected!', 'boei-help') . '</strong> ' . esc_html__('Your Boei widget is active on this site.', 'boei-help'); |
| 338 |
echo '</div>'; |
| 339 |
} |
| 340 |
|
| 341 |
// Dashboard cards |
| 342 |
echo '<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px;">'; |
| 343 |
|
| 344 |
$cards = array( |
| 345 |
array('url' => 'https://app.boei.help/inbox', 'icon' => '<svg width="32" height="32" fill="none" viewBox="0 0 24 24" stroke="#713eec" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"/></svg>', 'title' => __('Inbox', 'boei-help'), 'desc' => __('All messages', 'boei-help')), |
| 346 |
array('url' => 'https://app.boei.help/crm', 'icon' => '<svg width="32" height="32" fill="none" viewBox="0 0 24 24" stroke="#713eec" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"/></svg>', 'title' => __('CRM', 'boei-help'), 'desc' => __('Manage leads', 'boei-help')), |
| 347 |
array('url' => 'https://app.boei.help/analytics', 'icon' => '<svg width="32" height="32" fill="none" viewBox="0 0 24 24" stroke="#713eec" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/></svg>', 'title' => __('Analytics', 'boei-help'), 'desc' => __('Track performance', 'boei-help')), |
| 348 |
array('url' => 'https://app.boei.help/domains', 'icon' => '<svg width="32" height="32" fill="none" viewBox="0 0 24 24" stroke="#713eec" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/></svg>', 'title' => __('Widget', 'boei-help'), 'desc' => __('Customize', 'boei-help')), |
| 349 |
); |
| 350 |
|
| 351 |
foreach ($cards as $card) { |
| 352 |
echo '<a href="' . esc_url($card['url'] . '?utm_source=wp_plugin&utm_medium=plugin_admin&utm_campaign=dashboard_cards') . '" target="_blank" rel="noopener noreferrer" style="text-decoration: none;">'; |
| 353 |
echo '<span class="boei-card" style="display: block; background: #fff; border: 1px solid #c3c4c7; border-radius: 4px; padding: 20px; text-align: center; transition: border-color 0.2s; box-shadow: 0 1px 1px rgba(0,0,0,.04);">'; |
| 354 |
echo '<span style="display: block; margin-bottom: 8px;">' . wp_kses($card['icon'], boei_allowed_svg_tags()) . '</span>'; |
| 355 |
echo '<span style="display: block; font-weight: 600; color: #1d2327; font-size: 14px;">' . esc_html($card['title']) . '</span>'; |
| 356 |
echo '<span style="display: block; font-size: 12px; color: #646970; margin-top: 4px;">' . esc_html($card['desc']) . '</span>'; |
| 357 |
echo '</span>'; |
| 358 |
echo '</a>'; |
| 359 |
} |
| 360 |
|
| 361 |
echo '</div>'; |
| 362 |
|
| 363 |
// Review request box |
| 364 |
echo '<div style="background: linear-gradient(135deg, #713eec 0%, #9b6df5 100%); border-radius: 4px; padding: 20px; margin-bottom: 24px; color: #fff;">'; |
| 365 |
echo '<div style="display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px;">'; |
| 366 |
echo '<div>'; |
| 367 |
echo '<div style="font-weight: 600; font-size: 15px; margin-bottom: 4px;">' . esc_html__('Enjoying Boei? Help us grow!', 'boei-help') . '</div>'; |
| 368 |
echo '<div style="font-size: 13px; opacity: 0.9;">' . esc_html__('Your review helps other WordPress users discover Boei.', 'boei-help') . '</div>'; |
| 369 |
echo '</div>'; |
| 370 |
echo '<a href="https://wordpress.org/support/plugin/boei-help/reviews/#new-post" target="_blank" rel="noopener noreferrer" style="background: #fff; color: #713eec; padding: 10px 20px; border-radius: 4px; text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap;">' . esc_html__('Leave a review', 'boei-help') . '</a>'; |
| 371 |
echo '</div>'; |
| 372 |
echo '</div>'; |
| 373 |
|
| 374 |
// Settings section |
| 375 |
echo '<div style="background: #fff; border: 1px solid #c3c4c7; border-radius: 4px; padding: 20px; margin-bottom: 16px;">'; |
| 376 |
echo '<h3 style="margin: 0 0 12px 0; font-size: 14px;">' . esc_html__('Widget Key', 'boei-help') . '</h3>'; |
| 377 |
|
| 378 |
// Display mode (default) |
| 379 |
echo '<div id="boei-key-display" style="display: flex; gap: 10px; align-items: center; flex-wrap: wrap;">'; |
| 380 |
echo '<div style="display: flex; align-items: center; gap: 8px; background: #f0f6fc; border: 1px solid #c3c4c7; border-radius: 4px; padding: 8px 12px; font-family: monospace; font-size: 13px;">'; |
| 381 |
echo '<svg width="16" height="16" viewBox="0 0 20 20" fill="#00a32a"><path d="M10 2a8 8 0 100 16 8 8 0 000-16zm3.707 6.707l-4 4a1 1 0 01-1.414 0l-2-2a1 1 0 111.414-1.414L9 10.586l3.293-3.293a1 1 0 111.414 1.414z"/></svg>'; |
| 382 |
echo '<span>' . esc_html(boei_get_key()) . '</span>'; |
| 383 |
echo '</div>'; |
| 384 |
echo '<button type="button" class="button" onclick="boeiShowEdit()">' . esc_html__('Edit', 'boei-help') . '</button>'; |
| 385 |
echo '<button type="button" class="button" onclick="boeiDeactivate()" style="color: #d63638;">' . esc_html__('Deactivate', 'boei-help') . '</button>'; |
| 386 |
echo '</div>'; |
| 387 |
|
| 388 |
// Edit mode (hidden by default) |
| 389 |
echo '<div id="boei-key-edit" style="display: none;">'; |
| 390 |
echo '<form action="options.php" method="POST" style="display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap;">'; |
| 391 |
settings_fields('boei_key'); |
| 392 |
do_settings_sections('boei_key'); |
| 393 |
echo '<input type="text" name="boei_key_option" value="' . esc_attr(boei_get_key()) . '" style="flex: 1; min-width: 250px; max-width: 400px;" />'; |
| 394 |
echo '<button type="button" id="boei-test-btn" onclick="boeiTestKey()" class="button">' . esc_html__('Test', 'boei-help') . '</button>'; |
| 395 |
submit_button(__('Update', 'boei-help'), 'secondary', 'submit', false); |
| 396 |
echo '<button type="button" class="button" onclick="boeiCancelEdit()">' . esc_html__('Cancel', 'boei-help') . '</button>'; |
| 397 |
echo '</form>'; |
| 398 |
echo '<span id="boei-test-result" style="display: block; margin-top: 8px;"></span>'; |
| 399 |
echo '</div>'; |
| 400 |
|
| 401 |
// Deactivate form (hidden) |
| 402 |
echo '<form id="boei-deactivate-form" action="options.php" method="POST" style="display: none;">'; |
| 403 |
settings_fields('boei_key'); |
| 404 |
echo '<input type="hidden" name="boei_key_option" value="" />'; |
| 405 |
echo '</form>'; |
| 406 |
|
| 407 |
echo '</div>'; |
| 408 |
|
| 409 |
} else { |
| 410 |
// ========== ONBOARDING STATE ========== |
| 411 |
echo '<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; align-items: stretch;">'; |
| 412 |
|
| 413 |
// Left column - Value prop & features |
| 414 |
echo '<div style="background: linear-gradient(135deg, #713eec 0%, #9b6df5 100%); border-radius: 8px; padding: 32px; color: #fff; display: flex; flex-direction: column;">'; |
| 415 |
echo '<h2 style="margin: 0 0 16px 0; font-size: 28px; font-weight: 700; color: #fff; line-height: 1.2;">' . esc_html__('Capture Every Lead. Reply Instantly. Close More Deals.', 'boei-help') . '</h2>'; |
| 416 |
echo '<p style="margin: 0 0 24px 0; opacity: 0.9; font-size: 15px; line-height: 1.5;">' . esc_html__('Turn your WordPress site into a lead generation machine with AI-powered chat and 50+ contact channels.', 'boei-help') . '</p>'; |
| 417 |
|
| 418 |
// Feature list |
| 419 |
echo '<div style="display: flex; flex-direction: column; gap: 16px;">'; |
| 420 |
|
| 421 |
$features = array( |
| 422 |
array('icon' => '<svg width="20" height="20" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"/></svg>', 'text' => __('AI chatbot answers questions 24/7', 'boei-help')), |
| 423 |
array('icon' => '<svg width="20" height="20" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M17 8h2a2 2 0 012 2v6a2 2 0 01-2 2h-2v4l-4-4H9a1.994 1.994 0 01-1.414-.586m0 0L11 14h4a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2v4l.586-.586z"/></svg>', 'text' => __('50+ contact channels in one widget', 'boei-help')), |
| 424 |
array('icon' => '<svg width="20" height="20" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"/></svg>', 'text' => __('Single inbox for all messages', 'boei-help')), |
| 425 |
array('icon' => '<svg width="20" height="20" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"/></svg>', 'text' => __('Built-in CRM to track leads', 'boei-help')), |
| 426 |
); |
| 427 |
|
| 428 |
foreach ($features as $feature) { |
| 429 |
echo '<div style="display: flex; align-items: center; gap: 12px;">'; |
| 430 |
echo '<div style="background: rgba(255,255,255,0.2); border-radius: 50%; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">' . wp_kses($feature['icon'], boei_allowed_svg_tags()) . '</div>'; |
| 431 |
echo '<span style="font-size: 14px;">' . esc_html($feature['text']) . '</span>'; |
| 432 |
echo '</div>'; |
| 433 |
} |
| 434 |
|
| 435 |
echo '</div>'; |
| 436 |
|
| 437 |
echo '<div style="margin-top: auto; padding-top: 24px; border-top: 1px solid rgba(255,255,255,0.2); font-size: 13px; opacity: 0.9;">'; |
| 438 |
echo esc_html__('Trusted by 10,000+ businesses worldwide', 'boei-help'); |
| 439 |
echo '</div>'; |
| 440 |
|
| 441 |
echo '</div>'; |
| 442 |
|
| 443 |
// Right column - Setup steps |
| 444 |
echo '<div style="background: #fff; border: 1px solid #c3c4c7; border-radius: 8px; padding: 32px; display: flex; flex-direction: column;">'; |
| 445 |
echo '<h3 style="margin: 0 0 24px 0; font-size: 18px;">' . esc_html__('Get started in 2 minutes', 'boei-help') . '</h3>'; |
| 446 |
|
| 447 |
// Step 1 |
| 448 |
echo '<div style="display: flex; gap: 16px; margin-bottom: 24px; padding-bottom: 24px; border-bottom: 1px solid #e0e0e0;">'; |
| 449 |
echo '<div style="background: #713eec; color: #fff; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; flex-shrink: 0;">1</div>'; |
| 450 |
echo '<div style="flex: 1;">'; |
| 451 |
echo '<div style="font-weight: 600; margin-bottom: 4px;">' . esc_html__('Create your free Boei account', 'boei-help') . '</div>'; |
| 452 |
echo '<div style="color: #646970; font-size: 13px; margin-bottom: 12px;">' . esc_html__('Set up your widget and AI chatbot in minutes', 'boei-help') . '</div>'; |
| 453 |
echo '<a href="' . esc_url($registerURL) . '" class="button button-primary" target="_blank" rel="noopener noreferrer" style="background: #713eec; border-color: #713eec;">' . esc_html__('Get started free', 'boei-help') . '</a>'; |
| 454 |
echo '</div>'; |
| 455 |
echo '</div>'; |
| 456 |
|
| 457 |
// Step 2 |
| 458 |
echo '<div style="display: flex; gap: 16px;">'; |
| 459 |
echo '<div style="background: #713eec; color: #fff; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; flex-shrink: 0;">2</div>'; |
| 460 |
echo '<div style="flex: 1;">'; |
| 461 |
echo '<div style="font-weight: 600; margin-bottom: 4px;">' . esc_html__('Connect your widget', 'boei-help') . '</div>'; |
| 462 |
echo '<div style="color: #646970; font-size: 13px; margin-bottom: 12px;">' . wp_kses( |
| 463 |
sprintf( |
| 464 |
/* translators: %s: link to Boei dashboard */ |
| 465 |
__('Paste your widget key from the %s', 'boei-help'), |
| 466 |
'<a href="' . esc_url($installationURL) . '" target="_blank" rel="noopener noreferrer">' . esc_html__('Boei dashboard', 'boei-help') . '</a>' |
| 467 |
), |
| 468 |
array('a' => array('href' => true, 'target' => true, 'rel' => true)) |
| 469 |
) . '</div>'; |
| 470 |
echo '<form action="options.php" method="POST">'; |
| 471 |
settings_fields('boei_key'); |
| 472 |
do_settings_sections('boei_key'); |
| 473 |
echo '<input type="text" name="boei_key_option" value="' . esc_attr(boei_get_key()) . '" style="width: 100%; margin-bottom: 12px;" placeholder="' . esc_attr__('e.g. 21424816-afa8-4f70-85f0-85ddfbcbcec6', 'boei-help') . '" />'; |
| 474 |
echo '<div style="display: flex; gap: 8px; align-items: center; flex-wrap: wrap;">'; |
| 475 |
submit_button(__('Connect widget', 'boei-help'), 'primary', 'submit', false, array('style' => 'background: #713eec; border-color: #713eec;')); |
| 476 |
echo '<button type="button" id="boei-test-btn" onclick="boeiTestKey()" class="button">' . esc_html__('Test', 'boei-help') . '</button>'; |
| 477 |
echo '</div>'; |
| 478 |
echo '<span id="boei-test-result" style="display: block; margin-top: 8px;"></span>'; |
| 479 |
echo '</form>'; |
| 480 |
echo '</div>'; |
| 481 |
echo '</div>'; |
| 482 |
|
| 483 |
echo '</div>'; |
| 484 |
|
| 485 |
echo '</div>'; |
| 486 |
} |
| 487 |
|
| 488 |
// Footer links (shown for both states) |
| 489 |
echo '<div style="display: flex; gap: 20px; flex-wrap: wrap; color: #646970; font-size: 13px; margin-top: 20px;">'; |
| 490 |
echo '<a href="' . esc_url($homepageURL) . '" target="_blank" rel="noopener noreferrer">' . esc_html__('Help & Support', 'boei-help') . '</a>'; |
| 491 |
echo '<a href="' . esc_url($roadmapURL) . '" target="_blank" rel="noopener noreferrer">' . esc_html__('Roadmap', 'boei-help') . '</a>'; |
| 492 |
echo '</div>'; |
| 493 |
|
| 494 |
echo '</div>'; |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
/** |
| 499 |
* Return app management URL |
| 500 |
*/ |
| 501 |
function boei_url_manage() |
| 502 |
{ |
| 503 |
return 'https://app.boei.help?utm_source=wp_plugin&utm_medium=plugin_admin&utm_campaign=settings_page'; |
| 504 |
} |
| 505 |
|
| 506 |
/** |
| 507 |
* Return Boei homepage |
| 508 |
*/ |
| 509 |
function boei_url_homepage() |
| 510 |
{ |
| 511 |
return 'https://www.boei.help/?utm_source=wp_plugin&utm_medium=plugin_admin&utm_campaign=footer_support'; |
| 512 |
} |
| 513 |
|
| 514 |
/** |
| 515 |
* Return Boei logo |
| 516 |
*/ |
| 517 |
function boei_url_logo() |
| 518 |
{ |
| 519 |
return plugins_url('logo.svg', __FILE__); |
| 520 |
} |
| 521 |
|
| 522 |
/** |
| 523 |
* Verify widget key on plugin activation |
| 524 |
*/ |
| 525 |
function boei_activation() |
| 526 |
{ |
| 527 |
$key = get_option('boei_key_option'); |
| 528 |
if (!empty($key)) { |
| 529 |
$is_valid = boei_verify_key($key); |
| 530 |
if (!$is_valid) { |
| 531 |
set_transient('boei_activation_notice', 'invalid_key', 30); |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
register_activation_hook(__FILE__, 'boei_activation'); |
| 537 |
|
| 538 |
/** |
| 539 |
* Show admin notice if widget key is not configured |
| 540 |
*/ |
| 541 |
function boei_admin_notices() |
| 542 |
{ |
| 543 |
// Don't show on Boei settings page |
| 544 |
$screen = get_current_screen(); |
| 545 |
if ($screen && $screen->id === 'toplevel_page_boei-help-settings') { |
| 546 |
return; |
| 547 |
} |
| 548 |
|
| 549 |
// Show notice after activation if key is invalid |
| 550 |
if (get_transient('boei_activation_notice') === 'invalid_key') { |
| 551 |
delete_transient('boei_activation_notice'); |
| 552 |
echo '<div class="notice notice-error is-dismissible">'; |
| 553 |
echo '<p><strong>Boei:</strong> ' . esc_html__('Your widget key could not be verified. Please check your settings.', 'boei-help') . ' '; |
| 554 |
echo '<a href="' . esc_url(admin_url('admin.php?page=boei-help-settings')) . '">' . esc_html__('Go to settings', 'boei-help') . '</a></p>'; |
| 555 |
echo '</div>'; |
| 556 |
return; |
| 557 |
} |
| 558 |
|
| 559 |
// Show setup notice if widget key is not configured |
| 560 |
if (empty(boei_get_key())) { |
| 561 |
echo '<div class="notice notice-info">'; |
| 562 |
echo '<p><strong>Boei</strong> ' . esc_html__('Connect your widget to start capturing leads.', 'boei-help') . ' '; |
| 563 |
echo '<a href="' . esc_url(admin_url('admin.php?page=boei-help-settings')) . '">' . esc_html__('Go to settings', 'boei-help') . '</a></p>'; |
| 564 |
echo '</div>'; |
| 565 |
} |
| 566 |
} |
| 567 |
|
| 568 |
add_action('admin_notices', 'boei_admin_notices'); |
| 569 |
|
| 570 |
/** |
| 571 |
* Clean up plugin data on uninstall |
| 572 |
*/ |
| 573 |
function boei_uninstall() |
| 574 |
{ |
| 575 |
delete_option('boei_key_option'); |
| 576 |
} |
| 577 |
|
| 578 |
register_uninstall_hook(__FILE__, 'boei_uninstall'); |
| 579 |
|
| 580 |
|