PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.3.8
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.3.8
8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 8.5.4 8.5.3 8.5.2 All 533 releases
← All changes | includes/class-qcld-bot-rag.php +52 -61 8.5.28.3.8 View file →
@@ -280,9 +280,9 @@
280 280
281 281 $upload = wp_handle_upload($file_array, ['test_form' => false]);
282 282
283 283 if (isset($upload['error'])) {
284 - echo "<p>Error uploading: " . esc_html($filename) . "</p>";
284 + echo "<p>Error uploading: {$filename}</p>";
285 285 continue;
286 286 }
287 287
288 288 $file_url = $upload['url'];
@@ -287,9 +287,9 @@
287 287
288 288 $file_url = $upload['url'];
289 289 $file_path = $upload['file'];
290 290
291 - echo "<p>Uploaded: " . esc_html($filename) . "</p>";
291 + echo "<p>Uploaded: $filename</p>";
292 292
293 293 $handle = fopen($file_path, 'r'); // phpcs:ignore WordPress.WP.AlternativeFunctions
294 294 if ($handle === false) {
295 295 echo "<p style='color:red;'>Failed to open CSV file</p>";
@@ -302,9 +302,9 @@
302 302 fclose($handle); // phpcs:ignore WordPress.WP.AlternativeFunctions
303 303 continue;
304 304 }
305 305
306 - echo "<p>Columns: " . esc_html( implode(', ', $header) ) . "</p>";
306 + echo "<p>Columns: " . implode(', ', $header) . "</p>";
307 307
308 308 global $wpdb;
309 309 $table = $wpdb->prefix . "rag_documents";
310 310 $row_count = 0;
@@ -324,16 +324,15 @@
324 324 continue;
325 325 }
326 326 $embedding = $this->generate_embedding($content);
327 327 if (empty($embedding)) {
328 - echo "<p style='color:red;'>Failed embedding for row " . esc_html($row_count) . "</p>";
328 + echo "<p style='color:red;'>Failed embedding for row $row_count</p>";
329 329 continue;
330 330 }
331 331
332 332 $title = !empty($row[0]) ? substr($row[0], 0, 100) : "CSV Row $row_count";
333 333
334 - $result = $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
335 - $table, [
334 + $result = $wpdb->insert($table, [
336 335 'title' => sanitize_text_field($title),
337 336 'content' => $content,
338 337 'embedding' => wp_json_encode($embedding),
339 338 'source_type' => 'csv',
@@ -346,14 +345,14 @@
346 345
347 346 if ($result !== false) {
348 347 $success_count++;
349 348 } else {
350 - echo "<p style='color:red;'>DB error row " . esc_html($row_count) . ": " . esc_html($wpdb->last_error) . "</p>";
349 + echo "<p style='color:red;'>DB error row $row_count: " . $wpdb->last_error . "</p>";
351 350 }
352 351 }
353 352
354 353 fclose($handle); // phpcs:ignore WordPress.WP.AlternativeFunctions
355 - echo "<p style='color:green;'>✓ Processed " . esc_html($success_count) . " of " . esc_html($row_count) . " rows</p>";
354 + echo "<p style='color:green;'>✓ Processed $success_count of $row_count rows</p>";
356 355 }
357 356
358 357 echo "<h3>CSV Processing Complete!</h3>";
359 358 }
@@ -379,9 +378,9 @@
379 378
380 379 $upload = wp_handle_upload($file_array, ['test_form' => false]);
381 380
382 381 if (isset($upload['error'])) {
383 - echo "<p>Error uploading: " . esc_html($filename) . "</p>";
382 + echo "<p>Error uploading: {$filename}</p>";
384 383 continue;
385 384 }
386 385
387 386 $file_url = $upload['url'];
@@ -386,9 +385,9 @@
386 385
387 386 $file_url = $upload['url'];
388 387 $file_path = $upload['file'];
389 388
390 - echo "<p>Uploaded: " . esc_html($filename) . "</p>";
389 + echo "<p>Uploaded: $filename</p>";
391 390
392 391 // Extract PDF text (uses Smalot/PdfParser)
393 392 if (!class_exists('\Smalot\PdfParser\Parser')) {
394 393 echo "<p>PDF parser missing! Install `smalot/pdfparser`.</p>";
@@ -398,15 +397,15 @@
398 397 $parser = new \Smalot\PdfParser\Parser();
399 398 $pdf = $parser->parseFile($file_path);
400 399 $text = $pdf->getText();
401 400
402 - echo "<p>Extracted text length: " . esc_html(strlen($text)) . "</p>";
401 + echo "<p>Extracted text length: ".strlen($text)."</p>";
403 402
404 403 // Generate Embedding
405 404 $embedding = $this->generate_embedding($text);
406 405
407 406 if (empty($embedding)) {
408 - echo "<p style='color:red;'>Failed to generate embedding for: " . esc_html($filename) . "</p>";
407 + echo "<p style='color:red;'>Failed to generate embedding for: $filename</p>";
409 408 continue;
410 409 }
411 410
412 411 // Save to DB
@@ -412,10 +411,9 @@
412 411 // Save to DB
413 412 global $wpdb;
414 413 $table = $wpdb->prefix . "rag_documents";
415 414
416 - $result = $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
417 - $table, [
415 + $result = $wpdb->insert($table, [
418 416 'title' => sanitize_text_field($filename),
419 417 'content' => $text,
420 418 'embedding' => wp_json_encode($embedding),
421 419 'source_type' => 'pdf',
@@ -426,11 +424,11 @@
426 424 'created_at' => current_time('mysql')
427 425 ]);
428 426
429 427 if ($result === false) {
430 - echo "<p style='color:red;'>Database error: " . esc_html($wpdb->last_error) . "</p>";
428 + echo "<p style='color:red;'>Database error: " . $wpdb->last_error . "</p>";
431 429 } else {
432 - echo "<p style='color:green;'>✓ Saved PDF embedding for: " . esc_html($filename) . " (ID: " . esc_html($wpdb->insert_id) . ")</p>";
430 + echo "<p style='color:green;'>✓ Saved PDF embedding for: $filename (ID: " . $wpdb->insert_id . ")</p>";
433 431 }
434 432 }
435 433
436 434 echo "<h3>PDF Processing Complete!</h3>";
@@ -461,9 +459,9 @@
461 459 'test_type' => false, // Bypass mime type check
462 460 ]);
463 461
464 462 if (isset($upload['error'])) {
465 - echo "<p>Error uploading " . esc_html($filename) . ": " . esc_html($upload['error']) . "</p>";
463 + echo "<p>Error uploading {$filename}: " . $upload['error'] . "</p>";
466 464 continue;
467 465 }
468 466
469 467 $file_url = $upload['url'];
@@ -468,9 +466,9 @@
468 466
469 467 $file_url = $upload['url'];
470 468 $file_path = $upload['file'];
471 469
472 - echo "<p>Uploaded: " . esc_html($filename) . "</p>";
470 + echo "<p>Uploaded: $filename</p>";
473 471
474 472 // Read XAML/XML content
475 473 global $wp_filesystem;
476 474 if ( empty( $wp_filesystem ) ) {
@@ -479,9 +477,9 @@
479 477 }
480 478 $xml_content = $wp_filesystem->get_contents( $file_path );
481 479
482 480 if (empty($xml_content)) {
483 - echo "<p style='color:red;'>Failed to read file or file is empty: " . esc_html($filename) . "</p>";
481 + echo "<p style='color:red;'>Failed to read file or file is empty: $filename</p>";
484 482 continue;
485 483 }
486 484
487 485 // Attempt to parse as XML
@@ -530,9 +528,9 @@
530 528 // Generate Embedding
531 529 $embedding = $this->generate_embedding($clean_content);
532 530
533 531 if (empty($embedding)) {
534 - echo "<p style='color:red;'>Failed to generate embedding for item: " . esc_html($item_data['title']) . "</p>";
532 + echo "<p style='color:red;'>Failed to generate embedding for item: {$item_data['title']}</p>";
535 533 continue;
536 534 }
537 535
538 536 // Save to DB
@@ -538,10 +536,9 @@
538 536 // Save to DB
539 537 global $wpdb;
540 538 $table = $wpdb->prefix . "rag_documents";
541 539
542 - $result = $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
543 - $table, [
540 + $result = $wpdb->insert($table, [
544 541 'title' => sanitize_text_field($item_data['title']),
545 542 'content' => $clean_content,
546 543 'embedding' => wp_json_encode($embedding),
547 544 'source_type' => 'xaml',
@@ -552,11 +549,11 @@
552 549 'created_at' => current_time('mysql')
553 550 ]);
554 551
555 552 if ($result === false) {
556 - echo "<p style='color:red;'>Database error for item " . esc_html($item_data['title']) . ": " . esc_html($wpdb->last_error) . "</p>";
553 + echo "<p style='color:red;'>Database error for item {$item_data['title']}: " . $wpdb->last_error . "</p>";
557 554 } else {
558 - echo "<p style='color:green;'>✓ Saved embedding for: " . esc_html($item_data['title']) . " (ID: " . esc_html($wpdb->insert_id) . ")</p>";
555 + echo "<p style='color:green;'>✓ Saved embedding for: {$item_data['title']} (ID: " . $wpdb->insert_id . ")</p>";
559 556 }
560 557 }
561 558 }
562 559
@@ -580,9 +577,9 @@
580 577 if (strlen($content) < 20) continue;
581 578
582 579 $embedding = $this->wp_rag_create_embedding($content, $apiKey);
583 580
584 - $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
581 + $wpdb->insert(
585 582 $wpdb->prefix . "rag_documents",
586 583 [
587 584 "title" => $p->post_title,
588 585 "content" => $content,
@@ -668,10 +665,9 @@
668 665
669 666 $table = $wpdb->prefix . "rag_documents";
670 667
671 668 // Check if this post already exists in the database
672 - $existing = $wpdb->get_row( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
673 - $wpdb->prepare(
669 + $existing = $wpdb->get_row($wpdb->prepare(
674 670 "SELECT id FROM $table WHERE metadata LIKE %s AND source_type = %s",
675 671 '%"post_id":' . $p->ID . '%',
676 672 $p->post_type
677 673 ));
@@ -689,9 +685,9 @@
689 685 ];
690 686
691 687 if ($existing) {
692 688 // Update existing record
693 - $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
689 + $wpdb->update(
694 690 $table,
695 691 $data,
696 692 ['id' => $existing->id]
697 693 );
@@ -698,9 +694,9 @@
698 694 echo "<li style='color:blue;'>✓ Updated: " . esc_html($p->post_title) . " (" . esc_html($p->post_type) . ")</li>";
699 695 $updated_count++;
700 696 } else {
701 697 // Insert new record
702 - $wpdb->insert($table, $data); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
698 + $wpdb->insert($table, $data);
703 699 echo "<li style='color:green;'>✓ Embedded: " . esc_html($p->post_title) . " (" . esc_html($p->post_type) . ")</li>";
704 700 $inserted_count++;
705 701 }
706 702
@@ -715,9 +711,9 @@
715 711
716 712 // Simple Text Responses Embedding
717 713 if (get_option('rag_embed_str') == '1') {
718 714 $str_table = $wpdb->prefix . 'wpbot_response';
719 - $str_results = $wpdb->get_results("SELECT * FROM $str_table"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
715 + $str_results = $wpdb->get_results("SELECT * FROM $str_table");
720 716
721 717 if (!empty($str_results)) {
722 718 foreach ($str_results as $str) {
723 719 $content = "Query: " . $str->query . "\n";
@@ -737,10 +733,9 @@
737 733 continue;
738 734 }
739 735
740 736 // Check if this STR already exists in the RAG database
741 - $existing = $wpdb->get_row( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
742 - $wpdb->prepare(
737 + $existing = $wpdb->get_row($wpdb->prepare(
743 738 "SELECT id FROM $table WHERE metadata LIKE %s AND source_type = %s",
744 739 '%"str_id":' . $str->id . '%',
745 740 'str'
746 741 ));
@@ -757,13 +752,13 @@
757 752 "created_at" => current_time('mysql')
758 753 ];
759 754
760 755 if ($existing) {
761 - $wpdb->update($table, $data, ['id' => $existing->id]); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
756 + $wpdb->update($table, $data, ['id' => $existing->id]);
762 757 echo "<li style='color:blue;'>✓ Updated STR: " . esc_html($str->query) . "</li>";
763 758 $updated_count++;
764 759 } else {
765 - $wpdb->insert($table, $data); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
760 + $wpdb->insert($table, $data);
766 761 echo "<li style='color:green;'>✓ Embedded STR: " . esc_html($str->query) . "</li>";
767 762 $inserted_count++;
768 763 }
769 764
@@ -776,11 +771,11 @@
776 771 echo "</ul>";
777 772 echo "<h3>All Selected Sources Processed!</h3>";
778 773 echo "<p><strong>Summary:</strong></p>";
779 774 echo "<ul>";
780 - echo "<li>New entries created: <strong>" . esc_html($inserted_count) . "</strong></li>";
781 - echo "<li>Existing entries updated: <strong style='color:blue;'>" . esc_html($updated_count) . "</strong></li>";
782 - echo "<li>Skipped (too short): <strong>" . esc_html($skipped_count) . "</strong></li>";
775 + echo "<li>New entries created: <strong>$inserted_count</strong></li>";
776 + echo "<li>Existing entries updated: <strong style='color:blue;'>$updated_count</strong></li>";
777 + echo "<li>Skipped (too short): <strong>$skipped_count</strong></li>";
783 778 echo "</ul>";
784 779 }
785 780 public function wp_rag_create_embedding($text, $apiKey)
786 781 {
@@ -797,9 +792,9 @@
797 792 }
798 793
799 794 global $wpdb;
800 795 $table = $wpdb->prefix . 'rag_documents';
801 - $doc = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table WHERE id = %d", $doc_id)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
796 + $doc = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table WHERE id = %d", $doc_id));
802 797
803 798 if (!$doc) {
804 799 wp_send_json_error(['message' => 'Document not found']);
805 800 }
@@ -838,9 +833,9 @@
838 833 global $wpdb;
839 834 $id = intval($_POST['id']);
840 835 $table_name = $wpdb->prefix . 'rag_documents';
841 836
842 - $deleted = $wpdb->delete($table_name, array('id' => $id)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
837 + $deleted = $wpdb->delete($table_name, array('id' => $id));
843 838
844 839 if ($deleted) {
845 840 wp_send_json_success('Document deleted successfully.');
846 841 } else {
@@ -861,9 +856,9 @@
861 856 $ids = array_map('intval', $_POST['ids']);
862 857 $table_name = $wpdb->prefix . 'rag_documents';
863 858
864 859 $ids_string = implode(',', $ids);
865 - $deleted = $wpdb->query("DELETE FROM $table_name WHERE id IN ($ids_string)"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
860 + $deleted = $wpdb->query("DELETE FROM $table_name WHERE id IN ($ids_string)");
866 861
867 862 if ($deleted !== false) {
868 863 wp_send_json_success('Selected documents deleted successfully.');
869 864 } else {
@@ -878,14 +873,14 @@
878 873
879 874 global $wpdb;
880 875 $table_name = $wpdb->prefix . 'rag_documents';
881 876
882 - $deleted = $wpdb->query("TRUNCATE TABLE $table_name"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
877 + $deleted = $wpdb->query("TRUNCATE TABLE $table_name");
883 878
884 879 // Some DBs might not support TRUNCATE on tables with foreign keys or other constraints,
885 880 // though rag_documents is likely simple. Fallback to DELETE.
886 881 if ($deleted === false) {
887 - $deleted = $wpdb->query("DELETE FROM $table_name"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
882 + $deleted = $wpdb->query("DELETE FROM $table_name");
888 883 }
889 884
890 885 if ($deleted !== false) {
891 886 wp_send_json_success('All documents deleted successfully.');
@@ -902,9 +897,9 @@
902 897 global $wpdb;
903 898 $id = intval($_POST['id']);
904 899 $table_name = $wpdb->prefix . 'rag_documents';
905 900
906 - $document = $wpdb->get_row($wpdb->prepare("SELECT id, title, content FROM $table_name WHERE id = %d", $id)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
901 + $document = $wpdb->get_row($wpdb->prepare("SELECT id, title, content FROM $table_name WHERE id = %d", $id));
907 902
908 903 if ($document) {
909 904 wp_send_json_success($document);
910 905 } else {
@@ -923,9 +918,9 @@
923 918 $content = sanitize_textarea_field(wp_unslash($_POST['content']));
924 919 $table_name = $wpdb->prefix . 'rag_documents';
925 920
926 921 // Re-generate embedding if content changed
927 - $old_content = $wpdb->get_var($wpdb->prepare("SELECT content FROM $table_name WHERE id = %d", $id)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
922 + $old_content = $wpdb->get_var($wpdb->prepare("SELECT content FROM $table_name WHERE id = %d", $id));
928 923
929 924 $update_data = array(
930 925 'title' => $title,
931 926 'content' => $content,
@@ -940,9 +935,9 @@
940 935 $update_data['status'] = 'error';
941 936 }
942 937 }
943 938
944 - $updated = $wpdb->update($table_name, $update_data, array('id' => $id)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
939 + $updated = $wpdb->update($table_name, $update_data, array('id' => $id));
945 940
946 941 if ($updated !== false) {
947 942 wp_send_json_success('Document updated successfully.');
948 943 } else {
@@ -990,13 +985,12 @@
990 985 global $wpdb;
991 986 $table = $wpdb->prefix . "rag_documents";
992 987
993 988 // Check if it already exists (by source_url or custom metadata if we had it)
994 - $existing = $wpdb->get_row($wpdb->prepare("SELECT id FROM $table WHERE source_url = %s", $url)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
989 + $existing = $wpdb->get_row($wpdb->prepare("SELECT id FROM $table WHERE source_url = %s", $url));
995 990
996 991 if ($existing) {
997 - $result = $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
998 - $table, [
992 + $result = $wpdb->update($table, [
999 993 'title' => sanitize_text_field($title),
1000 994 'content' => $content,
1001 995 'embedding' => wp_json_encode($embedding),
1002 996 'status' => 'complete',
@@ -1002,10 +996,9 @@
1002 996 'status' => 'complete',
1003 997 'created_at' => current_time('mysql')
1004 998 ], ['id' => $existing->id]);
1005 999 } else {
1006 - $result = $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
1007 - $table, [
1000 + $result = $wpdb->insert($table, [
1008 1001 'title' => sanitize_text_field($title),
1009 1002 'content' => $content,
1010 1003 'embedding' => wp_json_encode($embedding),
1011 1004 'source_type' => ($post->post_type === 'page' || $post->post_type === 'post') ? $post->post_type : 'xaml',
@@ -1075,9 +1068,9 @@
1075 1068 global $wpdb;
1076 1069 $table = $wpdb->prefix . "rag_documents";
1077 1070
1078 1071 // Get all embeddings and texts
1079 - $rows = $wpdb->get_results("SELECT content, embedding FROM $table WHERE status = 'complete'", ARRAY_A); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
1072 + $rows = $wpdb->get_results("SELECT content, embedding FROM $table WHERE status = 'complete'", ARRAY_A);
1080 1073
1081 1074 if (empty($rows)) {
1082 1075 return "No knowledge base found.";
1083 1076 }
@@ -1174,9 +1167,9 @@
1174 1167 }
1175 1168
1176 1169 // Simple Text Responses
1177 1170 if (get_option('rag_embed_str') == '1') {
1178 - $str_ids = $wpdb->get_col("SELECT id FROM {$wpdb->prefix}wpbot_response"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1171 + $str_ids = $wpdb->get_col("SELECT id FROM {$wpdb->prefix}wpbot_response");
1179 1172 foreach ($str_ids as $str_id) {
1180 1173 $queue[] = ['id' => $str_id, 'type' => 'str'];
1181 1174 }
1182 1175 }
@@ -1238,10 +1231,9 @@
1238 1231 $error_msg = is_wp_error($embedding) ? $embedding->get_error_message() : 'Failed to generate embedding';
1239 1232 wp_send_json_error($error_msg);
1240 1233 }
1241 1234
1242 - $existing = $wpdb->get_row( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
1243 - $wpdb->prepare(
1235 + $existing = $wpdb->get_row($wpdb->prepare(
1244 1236 "SELECT id FROM $table WHERE metadata LIKE %s AND source_type = %s",
1245 1237 '%"post_id":' . $p->ID . '%',
1246 1238 $p->post_type
1247 1239 ));
@@ -1258,18 +1250,18 @@
1258 1250 "created_at" => current_time('mysql')
1259 1251 ];
1260 1252
1261 1253 if ($existing) {
1262 - $wpdb->update($table, $data, ['id' => $existing->id]); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1254 + $wpdb->update($table, $data, ['id' => $existing->id]);
1263 1255 wp_send_json_success(['status' => 'updated', 'title' => $title]);
1264 1256 } else {
1265 - $wpdb->insert($table, $data); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
1257 + $wpdb->insert($table, $data);
1266 1258 wp_send_json_success(['status' => 'inserted', 'title' => $title]);
1267 1259 }
1268 1260
1269 1261 } elseif ($type === 'str') {
1270 1262 global $wpdb;
1271 - $str = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbot_response WHERE id = %d", $id)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1263 + $str = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbot_response WHERE id = %d", $id));
1272 1264 if (!$str) {
1273 1265 wp_send_json_error('STR not found');
1274 1266 }
1275 1267
@@ -1293,10 +1285,9 @@
1293 1285 }
1294 1286
1295 1287 $table = $wpdb->prefix . "rag_documents";
1296 1288
1297 - $existing = $wpdb->get_row( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
1298 - $wpdb->prepare(
1289 + $existing = $wpdb->get_row($wpdb->prepare(
1299 1290 "SELECT id FROM $table WHERE metadata LIKE %s AND source_type = %s",
1300 1291 '%"str_id":' . $str->id . '%',
1301 1292 'str'
1302 1293 ));
@@ -1313,11 +1304,11 @@
1313 1304 "created_at" => current_time('mysql')
1314 1305 ];
1315 1306
1316 1307 if ($existing) {
1317 - $wpdb->update($table, $data, ['id' => $existing->id]); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1308 + $wpdb->update($table, $data, ['id' => $existing->id]);
1318 1309 } else {
1319 - $wpdb->insert($table, $data); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
1310 + $wpdb->insert($table, $data);
1320 1311 }
1321 1312 wp_send_json_success(['status' => 'processed', 'title' => 'Simple Text Response ID ' . $id]);
1322 1313 }
1323 1314