PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 2.3.1
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v2.3.1
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / admin / custom_fields / set_add_form_field.php

set_add_form_field.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 2.3.1, at includes/admin/custom_fields/set_add_form_field.php

133 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 if (
7 check_ajax_referer('set_add_form_field', '_ajax_nonce', false) != 1
8 ) wp_send_json_error('Unauthorised request!', 400);
9
10 global $current_user, $wpdb, $wpscfunction;
11 if (!($current_user->ID && $current_user->has_cap('manage_options'))) {exit;}
12
13 $field_label = isset($_POST) && isset($_POST['field_label']) ? sanitize_text_field($_POST['field_label']) : '';
14 if (!$field_label) {exit;}
15
16 $extra_info = isset($_POST) && isset($_POST['extra_info']) ? sanitize_text_field($_POST['extra_info']) : '';
17
18 $personal_info = isset($_POST) && isset($_POST['personal_info']) ? intval($_POST['personal_info']) : '1';
19
20 $field_type = isset($_POST) && isset($_POST['field_type']) ? intval($_POST['field_type']) : '';
21 if (!$field_type) {exit;}
22
23 $wpsc_tf_placeholder_text = isset($_POST) && isset($_POST['wpsc_tf_placeholder_text']) ? sanitize_text_field($_POST['wpsc_tf_placeholder_text']) : '';
24
25 $field_opt = isset($_POST) && isset($_POST['field_options']) ? sanitize_textarea_field($_POST['field_options']) : '';
26 $field_options = $field_opt ? explode("\n", $field_opt) : array();
27
28 $field_types = $wpscfunction->get_custom_field_types();
29 if ($field_types[$field_type]['has_options']==1 && !$field_options) {exit;}
30
31 foreach ($field_options as $key => $value) {
32 $field_options[$key] = trim(sanitize_text_field($value));
33 }
34
35 $html_content = isset($_POST) && isset($_POST['html_content']) ? wp_kses_post(htmlspecialchars_decode($_POST['html_content'], ENT_QUOTES)) : '';
36
37 $required = isset($_POST) && isset($_POST['required']) ? intval($_POST['required']) : '1';
38
39 if($field_type == '22'){
40 $required = 0;
41 }
42
43 $time_format = isset($_POST) && isset($_POST['time_format']) ? intval($_POST['time_format']) : '12';
44
45 $width = isset($_POST) && isset($_POST['width']) ? sanitize_text_field($_POST['width']) : '1';
46 $date_range = isset($_POST) && isset($_POST['date_range']) ? sanitize_text_field($_POST['date_range']) : '';
47
48 $date_range_from = isset($_POST) && isset($_POST['date_range_from']) ? sanitize_text_field($_POST['date_range_from']) : '';
49 $date_range_to = isset($_POST) && isset($_POST['date_range_to']) ? sanitize_text_field($_POST['date_range_to']) : '';
50
51 $visibility = isset($_POST) && isset($_POST['visibility']) ? $wpscfunction->sanitize_array($_POST['visibility']) : array();
52 $wpsc_limit = isset($_POST) && isset($_POST['limit']) && $_POST['limit'] ? sanitize_text_field($_POST['limit']) : '0';
53
54 foreach ($visibility as $key => $value) {
55 $visibility[$key] = sanitize_text_field($value);
56 }
57 $field_label = stripslashes($field_label);
58 $extra_info = stripslashes($extra_info);
59
60 $term = wp_insert_term( $field_label, 'wpsc_ticket_custom_fields' );
61 if (!is_wp_error($term) && isset($term['term_id'])) {
62 $load_order = $wpdb->get_var("select max(meta_value) as load_order from {$wpdb->prefix}termmeta WHERE meta_key='wpsc_tf_load_order'");
63 add_term_meta ($term['term_id'], 'wpsc_tf_label', $field_label);
64 add_term_meta ($term['term_id'], 'wpsc_tf_extra_info', $extra_info);
65 add_term_meta ($term['term_id'], 'agentonly', '0');
66 add_term_meta ($term['term_id'], 'wpsc_tf_status', '1');
67 add_term_meta ($term['term_id'], 'wpsc_tf_type', $field_type);
68 add_term_meta ($term['term_id'], 'wpsc_tf_placeholder_text', $wpsc_tf_placeholder_text);
69 add_term_meta ($term['term_id'], 'wpsc_tf_options', $field_options);
70 add_term_meta ($term['term_id'], 'wpsc_tf_required', $required);
71 add_term_meta ($term['term_id'], 'wpsc_tf_width', $width);
72 add_term_meta ($term['term_id'], 'wpsc_date_range', $date_range);
73 add_term_meta ($term['term_id'], 'date_range_from', $date_range_from);
74 add_term_meta ($term['term_id'], 'date_range_to', $date_range_to);
75 add_term_meta ($term['term_id'], 'wpsc_tf_visibility', $visibility);
76 add_term_meta ($term['term_id'], 'wpsc_tf_personal_info', $personal_info);
77 add_term_meta ($term['term_id'], 'wpsc_tf_load_order', ++$load_order);
78 add_term_meta ($term['term_id'], 'wpsc_tf_limit', $wpsc_limit);
79 add_term_meta ($term['term_id'], 'wpsc_html_content', $html_content);
80 add_term_meta($term['term_id'],'wpsc_time_format',$time_format);
81 if ($field_types[$field_type]['allow_ticket_list']) {
82 add_term_meta ($term['term_id'], 'wpsc_allow_ticket_list', '1');
83 add_term_meta ($term['term_id'], 'wpsc_customer_ticket_list_status', '0');
84 add_term_meta ($term['term_id'], 'wpsc_agent_ticket_list_status', '0');
85 } else {
86 add_term_meta ($term['term_id'], 'wpsc_allow_ticket_list', '0');
87 }
88
89 if ($field_types[$field_type]['allow_ticket_filter']) {
90 add_term_meta ($term['term_id'], 'wpsc_allow_ticket_filter', '1');
91 add_term_meta ($term['term_id'], 'wpsc_ticket_filter_type', $field_types[$field_type]['ticket_filter_type']);
92 add_term_meta ($term['term_id'], 'wpsc_customer_ticket_filter_status', '0');
93 add_term_meta ($term['term_id'], 'wpsc_agent_ticket_filter_status', '0');
94 } else {
95 add_term_meta ($term['term_id'], 'wpsc_allow_ticket_filter', '0');
96 }
97
98 if ($field_types[$field_type]['allow_orderby']) {
99 add_term_meta ($term['term_id'], 'wpsc_allow_orderby', '1');
100 } else {
101 add_term_meta ($term['term_id'], 'wpsc_allow_orderby', '0');
102 }
103
104 $check_str = $wpscfunction->check_str_is_non_english($field_label);
105
106 if(!$check_str){
107 wp_update_term($term['term_id'],'wpsc_ticket_custom_fields',array('slug' => 'cust_'.$term['term_id']));
108 }
109
110 do_action('wpsc_set_add_form_field',$term['term_id']);
111
112 /**
113 * Update translation option for custom field label in order to support WPML
114 */
115 $custom_fields_localize = get_option('wpsc_custom_fields_localize');
116 if (!$custom_fields_localize) {
117 $custom_fields_localize = array();
118 }
119 $custom_fields_localize['custom_fields_' . $term['term_id']] = $field_label;
120 update_option('wpsc_custom_fields_localize', $custom_fields_localize);
121
122 $custom_fields_extra_info = get_option('wpsc_custom_fields_extra_info');
123 if (!$custom_fields_extra_info) {
124 $custom_fields_extra_info = array();
125 }
126 $custom_fields_extra_info['custom_fields_extra_info_' . $term['term_id']] = $extra_info;
127 update_option('wpsc_custom_fields_extra_info', $custom_fields_extra_info);
128
129 echo '{ "sucess_status":"1","messege":"'.__('Field added successfully.','supportcandy').'" }';
130 } else {
131 echo '{ "sucess_status":"0","messege":"'.__('An error occured while creating custom field.','supportcandy').'" }';
132 }
133