PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.36
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.36
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / Form_Builder / helpers / Create_Submission.php

Create_Submission.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.36, at includes/widgets/Form_Builder/helpers/Create_Submission.php

129 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace King_Addons;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8
9 class Create_Submission
10 {
11
12 public function __construct()
13 {
14 add_action('wp_ajax_king_addons_form_builder_submissions', [$this, 'add_to_submissions']);
15 add_action('wp_ajax_nopriv_king_addons_form_builder_submissions', [$this, 'add_to_submissions']);
16 add_action('save_post', [$this, 'update_submissions_post_meta']);
17 }
18
19 public function add_to_submissions()
20 {
21
22 $nonce = $_POST['nonce'];
23
24 if (!wp_verify_nonce($nonce, 'king-addons-js')) {
25 wp_send_json_error(array(
26 'message' => esc_html__('Security check failed.', 'king-addons'),
27 ));
28 }
29
30 // Add capability check
31 if (!current_user_can('read')) {
32 wp_send_json_error(array(
33 'message' => esc_html__('Insufficient permissions.', 'king-addons'),
34 ));
35 }
36
37 $new = [
38 'post_status' => 'publish',
39 'post_type' => 'king-addons-fb-sub'
40 ];
41
42 $post_id = wp_insert_post($new);
43
44 // Security fix: Validate and sanitize form_content before saving to database
45 $form_content = isset($_POST['form_content']) && is_array($_POST['form_content']) ? $_POST['form_content'] : [];
46
47 foreach ($form_content as $key => $value) {
48 if (!is_array($value) || count($value) < 3) {
49 continue; // Skip malformed fields
50 }
51
52 // Sanitize all form field data before saving
53 $sanitized_key = sanitize_key($key);
54 $sanitized_value = [
55 sanitize_text_field($value[0]), // field type
56 is_array($value[1]) ? array_map('sanitize_text_field', $value[1]) : sanitize_text_field($value[1]), // field value
57 sanitize_text_field($value[2]) // field label
58 ];
59
60 update_post_meta($post_id, $sanitized_key, $sanitized_value);
61 }
62
63 $sanitized_form_name = sanitize_text_field($_POST['form_name'] ?? '');
64 $sanitized_form_id = sanitize_text_field($_POST['form_id'] ?? '');
65 $sanitized_form_page = sanitize_text_field($_POST['form_page'] ?? '');
66 $sanitized_form_page_id = sanitize_text_field($_POST['form_page_id'] ?? '');
67
68 update_post_meta($post_id, 'king_addons_form_name', $sanitized_form_name);
69 update_post_meta($post_id, 'king_addons_form_id', $sanitized_form_id);
70 update_post_meta($post_id, 'king_addons_form_page', $sanitized_form_page);
71 update_post_meta($post_id, 'king_addons_form_page_id', $sanitized_form_page_id);
72 update_post_meta($post_id, 'king_addons_user_agent', sanitize_textarea_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])));
73 update_post_meta($post_id, 'king_addons_user_ip', Core::getClientIP());
74
75 if ($post_id) {
76 wp_send_json_success(array(
77 'action' => 'king_addons_form_builder_submissions',
78 'post_id' => $post_id,
79 'message' => esc_html__('Submission created successfully', 'king-addons'),
80 'status' => 'success'
81 // Security fix: Removed unsanitized form_content from response to prevent XSS
82 ));
83 } else {
84 wp_send_json_success(array(
85 'action' => 'king_addons_form_builder_submissions',
86 'post_id' => $post_id,
87 'message' => esc_html__('Submit action failed', 'king-addons'),
88 'status' => 'error'
89 ));
90 }
91 }
92
93 public function update_submissions_post_meta($post_id)
94 {
95 // Security fix: Validate nonce and capabilities
96 if (!current_user_can('edit_post', $post_id)) {
97 return;
98 }
99
100 if (isset($_POST['king_addons_submission_changes']) && !empty($_POST['king_addons_submission_changes'])) {
101 // Security fix: Sanitize JSON input and validate structure
102 $raw_changes = sanitize_textarea_field(stripslashes($_POST['king_addons_submission_changes']));
103 $changes = json_decode($raw_changes, true);
104
105 if (!is_array($changes)) {
106 return; // Invalid JSON structure
107 }
108
109 foreach ($changes as $key => $value) {
110 // Security fix: Validate and sanitize keys and values
111 $sanitized_key = sanitize_key($key);
112 if (empty($sanitized_key)) {
113 continue; // Skip invalid keys
114 }
115
116 // Sanitize values based on type
117 if (is_array($value)) {
118 $sanitized_value = array_map('sanitize_text_field', $value);
119 } else {
120 $sanitized_value = sanitize_text_field($value);
121 }
122
123 update_post_meta($post_id, $sanitized_key, $sanitized_value);
124 }
125 }
126 }
127 }
128
129 new Create_Submission();