-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced-wp-chat.php
More file actions
1155 lines (992 loc) · 44.1 KB
/
Copy pathadvanced-wp-chat.php
File metadata and controls
1155 lines (992 loc) · 44.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: Voxfor Secure Live Chat and AI Support
* Plugin URI: https://voxfor.com/plugins/secure-live-chat/
* Description: Professional secure live chat system with real-time messaging, advanced analytics, AI bot integration, and multi-language support.
* Version: 2.2.1
* Requires at least: 5.0
* Requires PHP: 7.4
* Author: Voxfor Team
* Author URI: https://voxfor.com/
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: voxfor-secure-live-chat-and-ai-support
* Domain Path: /languages
*
* Voxfor Secure Live Chat and AI Support is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* Voxfor Secure Live Chat and AI Support is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
// Prevent direct access
if (! defined('ABSPATH')) {
exit;
}
// Emergency disable check
if (defined('VOXFSELI_EMERGENCY_DISABLE') && VOXFSELI_EMERGENCY_DISABLE) {
return;
}
// Fix for JSON response errors - ensure clean output for AJAX requests
if (defined('DOING_AJAX') && DOING_AJAX && isset($_REQUEST['action']) && strpos(sanitize_text_field(wp_unslash($_REQUEST['action'])), 'voxfseli_') === 0) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- AJAX action check only
// Multiple levels of output buffering to catch all output
if (! ob_get_level()) {
ob_start();
}
ob_start();
// Handle errors properly in individual AJAX handlers instead of globally modifying PHP settings
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler -- Required for AJAX error handling
// Register shutdown function with highest priority
register_shutdown_function(
function () {
// Get all buffer levels and clean them
$output = '';
$levels = ob_get_level();
for ($i = 0; $i < $levels; $i++) {
$output .= ob_get_contents();
ob_end_clean();
}
// Check if headers have already been sent
if (headers_sent($file, $line)) {
return;
}
// Clean the output - remove any whitespace, PHP notices, or HTML
$cleaned_output = trim($output);
// Special handling for voxfseli_send_message to ensure clean response
$action = isset($_REQUEST['action']) ? sanitize_text_field(wp_unslash($_REQUEST['action'])) : 'unknown'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Action comparison only
// If we have output, validate and send it
if (! empty($cleaned_output)) {
// Check if it starts with JSON
if (preg_match('/^\s*[\{\[]/', $cleaned_output)) {
// Try to decode the JSON to validate it
$decoded = json_decode($cleaned_output, true);
if (json_last_error() === JSON_ERROR_NONE) {
// Valid JSON - send it with proper headers
header('Content-Type: application/json; charset=utf-8');
header('X-Content-Type-Options: nosniff');
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- JSON output is already validated and sanitized
echo $cleaned_output;
} else {
// Invalid JSON - send clean error response
header('Content-Type: application/json; charset=utf-8');
echo wp_json_encode(
array(
'success' => false,
'data' => array( 'message' => 'Response processing error. Please try again.' ),
)
);
}
} else {
// Output doesn't look like JSON
header('Content-Type: application/json; charset=utf-8');
echo wp_json_encode(
array(
'success' => false,
'data' => array( 'message' => 'Server processing error. Please refresh and try again.' ),
)
);
}
} else {
// No output - for send_message, this is an error
if ('voxfseli_send_message' === $action) {
header('Content-Type: application/json; charset=utf-8');
echo wp_json_encode(
array(
'success' => false,
'data' => array( 'message' => 'Message processing failed. Please try again.' ),
)
);
}
}
}
);
}
// Check PHP version
if (version_compare(PHP_VERSION, '7.4', '<')) {
add_action(
'admin_notices',
function () {
echo '<div class="notice notice-error"><p><strong>Voxfor Secure Live Chat:</strong> This plugin requires PHP 7.4 or higher. Current version: ' . PHP_VERSION . '</p></div>';
}
);
return;
}
// Define plugin constants with proper checks to prevent redefinition
if (!defined('VOXFSELI_PLUGIN_VERSION')) {
define('VOXFSELI_PLUGIN_VERSION', '2.2.1');
}
if (!defined('VOXFSELI_PLUGIN_URL')) {
define('VOXFSELI_PLUGIN_URL', plugin_dir_url(__FILE__));
}
if (!defined('VOXFSELI_PLUGIN_PATH')) {
define('VOXFSELI_PLUGIN_PATH', plugin_dir_path(__FILE__));
}
if (!defined('VOXFSELI_PLUGIN_BASENAME')) {
define('VOXFSELI_PLUGIN_BASENAME', plugin_basename(__FILE__));
}
if (!defined('VOXFSELI_PLUGIN_FILE')) {
define('VOXFSELI_PLUGIN_FILE', __FILE__);
}
// Define lowercase versions for backward compatibility
if (!defined('voxfseli_PLUGIN_VERSION')) {
define('voxfseli_PLUGIN_VERSION', '2.2.1');
}
if (!defined('voxfseli_PLUGIN_URL')) {
define('voxfseli_PLUGIN_URL', plugin_dir_url(__FILE__));
}
if (!defined('voxfseli_PLUGIN_PATH')) {
define('voxfseli_PLUGIN_PATH', plugin_dir_path(__FILE__));
}
if (!defined('voxfseli_PLUGIN_BASENAME')) {
define('voxfseli_PLUGIN_BASENAME', plugin_basename(__FILE__));
}
if (!defined('voxfseli_PLUGIN_FILE')) {
define('voxfseli_PLUGIN_FILE', __FILE__);
}
if (!defined('VOXFSELI_PLUGIN_DIR')) {
define('VOXFSELI_PLUGIN_DIR', dirname(__FILE__));
}
if (!defined('VOXFSELI_PLUGIN_SLUG')) {
define('VOXFSELI_PLUGIN_SLUG', 'voxfor-secure-live-chat-and-ai-support');
}
if (!defined('VOXFSELI_MIN_WP_VERSION')) {
define('VOXFSELI_MIN_WP_VERSION', '5.0');
}
if (!defined('VOXFSELI_MIN_PHP_VERSION')) {
define('VOXFSELI_MIN_PHP_VERSION', '7.4');
}
// Debug settings should be configured in wp-config.php, not in plugins
// Error handling should be done properly within individual functions, not globally
// Include simplified chat system
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-simple-chat.php';
// Main plugin class - check if already defined to prevent fatal errors
if (!class_exists('VoxfseliChat')) {
class VoxfseliChat
{
private static $instance = null;
public static function get_instance()
{
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct()
{
// Only set up basic hooks in constructor
add_action('init', array( $this, 'init' ));
// WordPress automatically loads translations since 4.6 for plugins hosted on WordPress.org
// Register activation/deactivation hooks
register_activation_hook(__FILE__, array( $this, 'activate' ));
register_deactivation_hook(__FILE__, array( $this, 'deactivate' ));
register_uninstall_hook(__FILE__, array( 'VoxfseliChat', 'uninstall' ));
}
public function init()
{
// Load required files
$this->load_dependencies();
// Initialize components
$this->init_components();
// Add hooks
$this->add_hooks();
// Initialize performance optimizations
$this->init_performance_optimizations();
// Ensure AI interactions table exists (for existing installations)
$this->ensure_ai_table_exists();
// Schedule cleanup tasks
if (! wp_next_scheduled('voxfseli_cleanup_files')) {
wp_schedule_event(time(), 'daily', 'voxfseli_cleanup_files');
}
if (! wp_next_scheduled('voxfseli_cleanup_transients')) {
wp_schedule_event(time(), 'hourly', 'voxfseli_cleanup_transients');
}
}
private function load_dependencies()
{
// Check if we should use simplified chat system
$use_simple_chat = get_option('voxfseli_use_simple_chat', false);
if ($use_simple_chat) {
// Load only essential dependencies for simplified system
if (file_exists(VOXFSELI_PLUGIN_PATH . 'includes/functions.php')) {
require_once VOXFSELI_PLUGIN_PATH . 'includes/functions.php';
}
if (file_exists(VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-database.php')) {
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-database.php';
}
if (file_exists(VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-security.php')) {
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-security.php';
}
if (file_exists(VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-chat-widget.php')) {
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-chat-widget.php';
}
if (is_admin() && file_exists(VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-admin.php')) {
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-admin.php';
}
return; // Skip loading all other complex dependencies
}
// Load all dependencies for full system (original code)
// Loading core dependencies
require_once VOXFSELI_PLUGIN_PATH . 'includes/functions.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-database.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-security.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-permissions.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-chat-widget.php';
// Loading admin class
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-admin.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-ajax.php';
// Loading realtime class
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-realtime.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-analytics.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-file-handler.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-fingerprint.php';
// Load new simple tracking instead of old tracking
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-simple-user-tracking.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-notifications.php';
// Advanced features
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-bot.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-automations.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-advanced-analytics.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-ai-agent.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-auto-responder.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-integrations.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-mobile.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-templates.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-api.php';
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-knowledge-manager.php';
// ✅ NEW: AI Model Manager for dynamic model fetching
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-model-manager.php';
// Admin classes
require_once VOXFSELI_PLUGIN_PATH . 'admin/class-voxfseli-admin-bot.php';
}
private function init_components()
{
// Check if we should use simplified chat system
$use_simple_chat = get_option('voxfseli_use_simple_chat', false);
if ($use_simple_chat) {
// Initialize only essential components for simplified system
if (class_exists('VOXFSELI_Database')) {
VOXFSELI_Database::get_instance();
}
if (class_exists('VOXFSELI_Security')) {
VOXFSELI_Security::get_instance();
}
if (class_exists('VOXFSELI_Chat_Widget')) {
VOXFSELI_Chat_Widget::get_instance();
}
if (is_admin() && class_exists('VOXFSELI_Admin')) {
VOXFSELI_Admin::get_instance();
}
// The simplified chat system is already initialized via the include
return; // Skip initializing all other complex components
}
// Initialize all components for full system (original code)
VOXFSELI_Database::get_instance();
VOXFSELI_Security::get_instance();
VOXFSELI_Permissions::get_instance();
VOXFSELI_Chat_Widget::get_instance();
VOXFSELI_Admin::get_instance();
VOXFSELI_Ajax::get_instance();
VOXFSELI_Realtime::get_instance();
VOXFSELI_Analytics::get_instance();
VOXFSELI_File_Handler::get_instance();
VOXFSELI_Fingerprint::get_instance();
// Use new simple tracking instead of old tracking
if (class_exists('VOXFSELI_Simple_User_Tracking')) {
VOXFSELI_Simple_User_Tracking::get_instance();
}
VOXFSELI_Notifications::get_instance();
// Advanced features
VOXFSELI_Bot::get_instance();
VOXFSELI_Automations::get_instance();
VOXFSELI_Advanced_Analytics::get_instance();
VOXFSELI_AI_Agent::get_instance();
VOXFSELI_Auto_Responder::get_instance();
VOXFSELI_Integrations::get_instance();
VOXFSELI_Mobile::get_instance();
VOXFSELI_Templates::get_instance();
VOXFSELI_API::get_instance();
// Knowledge Manager
VOXFSELI_Knowledge_Manager::get_instance();
// Admin components
if (is_admin()) {
VOXFSELI_Admin_Bot::get_instance();
}
}
private function add_hooks()
{
add_action('wp_enqueue_scripts', array( $this, 'enqueue_frontend_scripts' ));
add_action('admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ));
add_action('wp_footer', array( $this, 'render_chat_widget' ));
add_action('wp_footer', array( $this, 'add_performance_monitoring' ));
add_action('voxfseli_cleanup_transients', array( $this, 'cleanup_old_transients' ));
add_action('admin_notices', array( $this, 'performance_admin_notice' ));
// Manifest file handlers removed
// Add database repair functionality
if (is_admin()) {
add_action('admin_menu', array( $this, 'add_database_repair_menu' ));
add_action('admin_init', array( $this, 'handle_database_repair' ));
}
}
/**
* Add database repair menu
*/
public function add_database_repair_menu()
{
add_submenu_page(
'tools.php',
'VOXFSELI Database Repair',
'VOXFSELI Database Repair',
'manage_options',
'voxfseli-database-repair',
array( $this, 'database_repair_page' )
);
}
/**
* Handle database repair form submission
*/
public function handle_database_repair()
{
$nonce = isset($_POST['voxfseli_repair_nonce']) ? sanitize_text_field(wp_unslash($_POST['voxfseli_repair_nonce'])) : '';
if (isset($_POST['voxfseli_repair_database']) && wp_verify_nonce($nonce, 'voxfseli_repair_database')) {
try {
// Load database class
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-database.php';
// Create database tables
$db = VOXFSELI_Database::get_instance();
$results = $db->create_tables();
// Create additional tables
if (class_exists('VOXFSELI_Automations')) {
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-automations.php';
VOXFSELI_Automations::get_instance()->create_tables();
}
if (class_exists('VOXFSELI_AI_Agent')) {
require_once VOXFSELI_PLUGIN_PATH . 'includes/class-voxfseli-ai-agent.php';
VOXFSELI_AI_Agent::create_ai_table();
}
add_action(
'admin_notices',
function () {
echo '<div class="notice notice-success"><p><strong>Database Repair Complete!</strong> All missing tables have been created. Try activating the plugin again.</p></div>';
}
);
} catch (Exception $e) {
add_action(
'admin_notices',
function () use ($e) {
echo '<div class="notice notice-error"><p><strong>Database Repair Failed:</strong> ' . esc_html($e->getMessage()) . '</p></div>';
}
);
}
}
}
/**
* Database repair page
*/
public function database_repair_page()
{
global $wpdb;
// Check which tables are missing
$required_tables = array(
'voxfseli_chats',
'voxfseli_messages',
'voxfseli_files',
'voxfseli_agents',
'voxfseli_banned_users',
'voxfseli_analytics',
'voxfseli_user_tracking',
'voxfseli_ai_interactions'
);
$missing_tables = array();
$existing_tables = array();
foreach ($required_tables as $table) {
$table_name = $wpdb->prefix . $table;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Database repair tool, table existence check
$result = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name));
if ($table_name === $result) {
$existing_tables[] = $table;
} else {
$missing_tables[] = $table;
}
}
?>
<div class="wrap">
<h1>🔧 VOXFSELI Database Repair Tool</h1>
<div class="notice notice-info">
<p><strong>Fix Database Issues:</strong> This tool helps repair missing database tables that are causing plugin activation failures.</p>
</div>
<div class="card">
<h2>📊 Database Status</h2>
<table class="form-table">
<tr>
<th>Existing Tables (<?php echo count($existing_tables); ?>)</th>
<td>
<?php if (!empty($existing_tables)): ?>
<span style="color: green;">✓ <?php echo esc_html(implode(', ', $existing_tables)); ?></span>
<?php else: ?>
<span style="color: red;">None found</span>
<?php endif; ?>
</td>
</tr>
<tr>
<th>Missing Tables (<?php echo count($missing_tables); ?>)</th>
<td>
<?php if (!empty($missing_tables)): ?>
<span style="color: red;">✗ <?php echo esc_html(implode(', ', $missing_tables)); ?></span>
<?php else: ?>
<span style="color: green;">All tables exist!</span>
<?php endif; ?>
</td>
</tr>
</table>
</div>
<?php if (!empty($missing_tables)): ?>
<div class="card">
<h2>🛠️ Repair Database</h2>
<form method="post" action="">
<?php wp_nonce_field('voxfseli_repair_database', 'voxfseli_repair_nonce'); ?>
<p>This will create the missing database tables:</p>
<ul>
<?php foreach ($missing_tables as $table): ?>
<li>✅ <?php echo esc_html($table); ?></li>
<?php endforeach; ?>
</ul>
<p>
<input type="submit" name="voxfseli_repair_database" class="button button-primary button-large" value="🔧 Repair Database Tables" />
</p>
</form>
</div>
<?php endif; ?>
<div class="card">
<h2>📋 Next Steps</h2>
<ol>
<li><strong>Run the repair tool above</strong> if you have missing tables</li>
<li><strong>Deactivate the old plugin</strong> if you have both versions active</li>
<li><strong>Try activating the plugin again</strong> after repair</li>
<li><strong>Check the error logs</strong> to confirm issues are resolved</li>
</ol>
</div>
</div>
<?php
// Enqueue admin styles
wp_enqueue_style(
'voxfseli-admin-quick-start',
VOXFSELI_PLUGIN_URL . 'includes/css/voxfseli-admin-quick-start.css',
array(),
VOXFSELI_PLUGIN_VERSION
);
?>
<?php
}
// load_textdomain() method removed - WordPress automatically loads translations since 4.6
public function enqueue_frontend_scripts()
{
// Skip if admin area
if (is_admin()) {
return;
}
// Check if chat should be loaded
if (! $this->should_load_chat()) {
return;
}
// Basic CSS and JS
wp_enqueue_script('jquery');
// Check if we should use the simplified chat system
$use_simple_chat = get_option('voxfseli_use_simple_chat', false);
if ($use_simple_chat) {
// Enqueue simplified frontend script
wp_enqueue_script(
'voxfseli-frontend-simple',
VOXFSELI_PLUGIN_URL . 'includes/js/frontend-simple.js',
array( 'jquery' ),
VOXFSELI_PLUGIN_VERSION,
true
);
$script_handle = 'voxfseli-frontend-simple';
} else {
// Enqueue standard frontend scripts
wp_enqueue_script(
'voxfseli-frontend-realtime',
VOXFSELI_PLUGIN_URL . 'includes/js/frontend-realtime.js',
array( 'jquery' ),
VOXFSELI_PLUGIN_VERSION,
true
);
wp_enqueue_script(
'voxfseli-frontend-complete',
VOXFSELI_PLUGIN_URL . 'includes/js/frontend-complete.js',
array( 'jquery', 'voxfseli-frontend-realtime' ),
VOXFSELI_PLUGIN_VERSION,
true
);
$script_handle = 'voxfseli-frontend-complete';
}
// Always enqueue automations and tracking scripts
wp_enqueue_script(
'voxfseli-automations',
VOXFSELI_PLUGIN_URL . 'includes/js/voxfseli-automations.js',
array( 'jquery', $script_handle ),
VOXFSELI_PLUGIN_VERSION,
true
);
wp_enqueue_script(
'voxfseli-simple-user-tracking',
VOXFSELI_PLUGIN_URL . 'includes/js/voxfseli-simple-user-tracking-frontend.js',
array( 'jquery' ),
VOXFSELI_PLUGIN_VERSION,
true
);
// Fingerprint script
wp_enqueue_script(
'voxfseli-fingerprint',
VOXFSELI_PLUGIN_URL . 'includes/js/fingerprint.js',
array( 'jquery' ),
VOXFSELI_PLUGIN_VERSION,
true
);
// Frontend CSS
wp_enqueue_style(
'voxfseli-frontend-style',
VOXFSELI_PLUGIN_URL . 'includes/css/frontend.css',
array(),
VOXFSELI_PLUGIN_VERSION
);
// Get widget settings
$widget_settings = voxfseli_get_widget_settings();
// Check if AI Agent is enabled
$main_settings = get_option('voxfseli_settings', array());
$ai_settings = isset($main_settings['ai_agent']) ? $main_settings['ai_agent'] : array();
$ai_enabled = ! empty($ai_settings['enabled']);
// Localize script with configuration
$config = array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('voxfseli_nonce'),
'plugin_url' => VOXFSELI_PLUGIN_URL,
'visitor_id' => $this->get_or_create_visitor_id(),
'ai_enabled' => $ai_enabled ? '1' : '0', // Add AI enabled status
'settings' => array(
'chat_enabled' => $widget_settings['enabled'],
'agent_online' => $this->check_agent_online(),
'welcome_message' => $widget_settings['welcome_message'],
'offline_message' => $widget_settings['offline_message'],
'widget_title' => $widget_settings['widget_title'],
'widget_position' => $widget_settings['widget_position'],
'widget_color' => $widget_settings['widget_color'],
'max_file_size' => $widget_settings['max_file_size'] ?? 5242880,
'allowed_file_types' => $widget_settings['allowed_file_types'] ?? array( 'jpg', 'jpeg', 'png', 'gif', 'pdf', 'doc', 'docx' ),
'use_simple_chat' => $use_simple_chat,
'polling_interval' => $widget_settings['polling_interval'] ?? 3000,
'show_powered_by' => $widget_settings['show_powered_by'] ?? true,
),
);
// Localize the main frontend script with configuration
wp_localize_script($script_handle, 'voxfseli_frontend', $config);
// Also localize automations script with same config to ensure it has access
wp_localize_script('voxfseli-automations', 'voxfseli_frontend', $config);
// Localize tracking script with necessary data
wp_localize_script(
'voxfseli-simple-user-tracking',
'voxfseliTracking',
array(
'sessionId' => session_id() ?: 'session_' . time(),
'visitorId' => $this->get_or_create_visitor_id(),
'ajaxurl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('voxfseli_tracking_nonce'),
'enabled' => '1',
'debug' => WP_DEBUG ? '1' : '0',
)
);
}
public function enqueue_admin_scripts($hook)
{
// Load on all VOXFSELI admin pages
if (strpos($hook, 'voxfor-secure-live-chat-and-ai-support') === false && strpos($hook, 'voxfseli-') === false) {
return;
}
$script_url = VOXFSELI_PLUGIN_URL . 'includes/js/admin.js';
wp_enqueue_script('voxfseli-admin', $script_url, array( 'jquery', 'wp-util' ), VOXFSELI_PLUGIN_VERSION, true);
wp_enqueue_style('voxfseli-admin', VOXFSELI_PLUGIN_URL . 'includes/css/admin.css', array(), VOXFSELI_PLUGIN_VERSION);
wp_localize_script(
'voxfseli-admin',
'voxfseli_admin',
array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('voxfseli_admin_nonce'),
'polling_interval' => 3000, // 3 seconds
'translations' => $this->get_admin_translations(),
)
);
}
public function render_chat_widget()
{
if (! $this->should_load_chat()) {
return;
}
// Ensure settings are enabled by default
$settings = get_option('voxfseli_settings', array());
if (! isset($settings['enabled'])) {
$settings['enabled'] = true;
update_option('voxfseli_settings', $settings);
}
// Use the original widget class that was working
VOXFSELI_Chat_Widget::get_instance()->render();
}
/**
* Check if chat should be loaded
*/
private function should_load_chat()
{
// Skip if admin area
if (is_admin()) {
return false;
}
// Check if chat is enabled
$settings = get_option('voxfseli_settings', array());
// Enable chat by default if no settings exist
if (empty($settings)) {
$settings = array( 'enabled' => true );
update_option('voxfseli_settings', $settings);
}
// Check if enabled
if (isset($settings['enabled']) && ! $settings['enabled']) {
return false;
}
return true;
}
/**
* Get or create visitor ID
*/
private function get_or_create_visitor_id()
{
// Start session if not already started
if (! session_id()) {
session_start();
}
// Try to get visitor ID from session
if (isset($_SESSION['voxfseli_visitor_id'])) {
return sanitize_text_field($_SESSION['voxfseli_visitor_id']);
}
// Create new visitor ID
$visitor_id = 'visitor_' . time() . '_' . wp_rand(1000, 9999);
$_SESSION['voxfseli_visitor_id'] = $visitor_id;
return $visitor_id;
}
/**
* Check if any agent is online
*/
private function check_agent_online()
{
if (! class_exists('VOXFSELI_Database')) {
return false;
}
try {
$db = VOXFSELI_Database::get_instance();
return $db->has_online_agents();
} catch (Exception $e) {
return false;
}
}
/**
* Enable simplified chat system
*/
public static function enable_simple_chat()
{
update_option('voxfseli_use_simple_chat', true);
}
/**
* Disable simplified chat system
*/
public static function disable_simple_chat()
{
update_option('voxfseli_use_simple_chat', false);
}
/**
* Get admin translations
*/
private function get_admin_translations()
{
return array(
'loading' => __('Loading...', 'voxfor-secure-live-chat-and-ai-support'),
'error' => __('Error', 'voxfor-secure-live-chat-and-ai-support'),
'success' => __('Success', 'voxfor-secure-live-chat-and-ai-support'),
'no_active_chats' => __('No active chats', 'voxfor-secure-live-chat-and-ai-support'),
'confirm_end_chat' => __('Are you sure you want to end this chat?', 'voxfor-secure-live-chat-and-ai-support'),
'confirm_ban_user' => __('Are you sure you want to ban this user?', 'voxfor-secure-live-chat-and-ai-support'),
'send_message' => __('Send Message', 'voxfor-secure-live-chat-and-ai-support'),
'end_chat' => __('End Chat', 'voxfor-secure-live-chat-and-ai-support'),
'ban_user' => __('Ban User', 'voxfor-secure-live-chat-and-ai-support'),
);
}
public function activate()
{
// Activation process starts
try {
// Load dependencies first - one by one to isolate the problematic file
require_once VOXFSELI_PLUGIN_PATH . "includes/functions.php";
require_once VOXFSELI_PLUGIN_PATH . "includes/class-voxfseli-database.php";
require_once VOXFSELI_PLUGIN_PATH . "includes/class-voxfseli-security.php";
require_once VOXFSELI_PLUGIN_PATH . "includes/class-voxfseli-permissions.php";
require_once VOXFSELI_PLUGIN_PATH . "includes/class-voxfseli-chat-widget.php";
require_once VOXFSELI_PLUGIN_PATH . "includes/class-voxfseli-admin.php";
require_once VOXFSELI_PLUGIN_PATH . "includes/class-voxfseli-ajax.php";
require_once VOXFSELI_PLUGIN_PATH . "includes/class-voxfseli-automations.php";
require_once VOXFSELI_PLUGIN_PATH . "includes/class-voxfseli-ai-agent.php";
} catch (Exception $e) {
wp_die("VOXFSELI Activation failed in load_dependencies: " . esc_html($e->getMessage()));
} catch (Error $e) {
wp_die("VOXFSELI Activation fatal error in load_dependencies: " . esc_html($e->getMessage()));
}
try {
// Create database tables
VOXFSELI_Database::get_instance()->create_tables();
// Create automation tables
if (class_exists("VOXFSELI_Automations")) {
VOXFSELI_Automations::get_instance()->create_tables();
}
// Create AI interactions table (ensure it's created)
if (class_exists("VOXFSELI_AI_Agent")) {
VOXFSELI_AI_Agent::create_ai_table();
// Verify AI table was created
global $wpdb;
$ai_table = $wpdb->prefix . 'voxfseli_ai_interactions';
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Table existence check during activation
$table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $ai_table));
}
// Use the complete default settings including AI settings
$default_settings = voxfseli_get_default_settings();
// Force update the settings
update_option("voxfseli_settings", $default_settings);
// Also create a marker that shows the plugin is properly activated
update_option("voxfseli_plugin_activated", true);
// Set default agent status to "Online" for admin users
$admin_users = get_users(array('role' => 'administrator'));
foreach ($admin_users as $admin_user) {
// Only set if no status exists yet
if (!get_user_meta($admin_user->ID, 'voxfseli_agent_status', true)) {
update_user_meta($admin_user->ID, 'voxfseli_agent_status', 'online');
update_user_meta($admin_user->ID, 'voxfseli_agent_status_text', __('Online', 'voxfor-secure-live-chat-and-ai-support'));
update_user_meta($admin_user->ID, 'voxfseli_last_activity', time());
}
}
// Initialize AI Agent and cache contact info
if (class_exists("VOXFSELI_AI_Agent")) {
$ai_agent = VOXFSELI_AI_Agent::get_instance();
$ai_agent->refresh_contact_cache();
}
} catch (Exception $e) {
wp_die("VOXFSELI Activation failed in main process: " . esc_html($e->getMessage()));
} catch (Error $e) {
wp_die("VOXFSELI Activation fatal error in main process: " . esc_html($e->getMessage()));
}
try {
// Create upload directory
$upload_dir = wp_upload_dir();
$voxfseli_upload_dir = $upload_dir["basedir"] . "/voxfseli-uploads";
if (! file_exists($voxfseli_upload_dir)) {
wp_mkdir_p($voxfseli_upload_dir);
// CRITICAL FILE UPLOAD FIX: Secure .htaccess creation with proper error handling
$htaccess_file = $voxfseli_upload_dir . "/.htaccess";
$htaccess_content = "# Voxfor Secure Live Chat Security\n";
$htaccess_content .= "deny from all\n";
$htaccess_content .= "<Files ~ \"\\.(jpg|jpeg|png|gif|webp|pdf|doc|docx|txt|rtf)$\">\n";
$htaccess_content .= " allow from all\n";
$htaccess_content .= "</Files>\n";
// Initialize WP_Filesystem
if (! function_exists('WP_Filesystem')) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
WP_Filesystem();
global $wp_filesystem;
if ($wp_filesystem && $wp_filesystem->put_contents($htaccess_file, $htaccess_content, FS_CHMOD_FILE)) {
// Success using WP_Filesystem
} else {
// Fallback with proper error handling using WP_Filesystem
if ($wp_filesystem && $wp_filesystem->is_writable($voxfseli_upload_dir)) {
$wp_filesystem->put_contents($htaccess_file, $htaccess_content, FS_CHMOD_FILE);
}
}
}
// Schedule cleanup cron
if (! wp_next_scheduled("voxfseli_cleanup_files")) {
wp_schedule_event(time(), "hourly", "voxfseli_cleanup_files");
}
// Manifest rewrite rule removed
// Flush rewrite rules
flush_rewrite_rules();
} catch (Exception $e) {
wp_die("VOXFSELI Activation failed in final setup: " . esc_html($e->getMessage()));
} catch (Error $e) {
wp_die("VOXFSELI Activation fatal error in final setup: " . esc_html($e->getMessage()));
}
}
public function deactivate()
{
// Clear scheduled events
wp_clear_scheduled_hook('voxfseli_cleanup_files');
// Flush rewrite rules
flush_rewrite_rules();
}
public static function uninstall()
{
// Remove database tables
VOXFSELI_Database::get_instance()->drop_tables();
// Remove options
delete_option('voxfseli_settings');
delete_option('voxfseli_analytics_data');
// Remove upload directory
$upload_dir = wp_upload_dir();
$voxfseli_upload_dir = $upload_dir['basedir'] . '/voxfseli-uploads';
if (file_exists($voxfseli_upload_dir)) {
// Remove all files
$files = glob($voxfseli_upload_dir . '/*');
foreach ($files as $file) {
if (is_file($file)) {
wp_delete_file($file);
}
}
global $wp_filesystem;
if (! $wp_filesystem) {
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
}
$wp_filesystem->rmdir($voxfseli_upload_dir, true);
}
// Clear scheduled events
wp_clear_scheduled_hook('voxfseli_cleanup_files');
}