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_agentonly_field.php

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

106 lines 4.9 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_agentonly_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_limit = isset($_POST) && isset($_POST['limit']) && $_POST['limit'] ? sanitize_text_field($_POST['limit']) : '0';
24 $date_range = isset($_POST) && isset($_POST['date_range']) ? sanitize_text_field($_POST['date_range']) : '';
25
26 $date_range_from = isset($_POST) && isset($_POST['date_range_from']) ? sanitize_text_field($_POST['date_range_from']) : '';
27 $date_range_to = isset($_POST) && isset($_POST['date_range_to']) ? sanitize_text_field($_POST['date_range_to']) : '';
28
29 $field_opt = isset($_POST) && isset($_POST['field_options']) ? sanitize_textarea_field($_POST['field_options']) : '';
30 $field_options = $field_opt ? explode("\n", $field_opt) : array();
31
32 $field_types = $wpscfunction->get_custom_field_types();
33 if ($field_types[$field_type]['has_options']==1 && !$field_options) {exit;}
34
35 foreach ($field_options as $key => $value) {
36 $field_options[$key] = trim(sanitize_text_field($value));
37 }
38 $field_label = stripslashes($field_label);
39
40 $time_format = isset($_POST) && isset($_POST['time_format']) ? intval($_POST['time_format']) : '12';
41
42 $term = wp_insert_term( $field_label, 'wpsc_ticket_custom_fields' );
43 if (!is_wp_error($term) && isset($term['term_id'])) {
44 $load_order = $wpdb->get_var("select max(meta_value) as load_order from {$wpdb->prefix}termmeta WHERE meta_key='wpsc_tf_load_order'");
45 add_term_meta ($term['term_id'], 'wpsc_tf_label', $field_label);
46 add_term_meta ($term['term_id'], 'wpsc_tf_extra_info', $extra_info);
47 add_term_meta ($term['term_id'], 'agentonly', '1');
48 add_term_meta ($term['term_id'], 'wpsc_tf_type', $field_type);
49 add_term_meta ($term['term_id'], 'wpsc_tf_options', $field_options);
50 add_term_meta ($term['term_id'], 'wpsc_tf_personal_info', $personal_info);
51 add_term_meta ($term['term_id'], 'wpsc_tf_load_order', ++$load_order);
52 add_term_meta ($term['term_id'], 'wpsc_tf_limit', $wpsc_limit);
53 add_term_meta ($term['term_id'], 'wpsc_date_range', $date_range);
54 add_term_meta ($term['term_id'], 'date_range_from', $date_range_from);
55 add_term_meta ($term['term_id'], 'date_range_to', $date_range_to);
56 add_term_meta($term['term_id'],'wpsc_time_format',$time_format);
57
58
59 if ($field_types[$field_type]['allow_ticket_list']) {
60 add_term_meta ($term['term_id'], 'wpsc_allow_ticket_list', '1');
61 add_term_meta ($term['term_id'], 'wpsc_customer_ticket_list_status', '0');
62 add_term_meta ($term['term_id'], 'wpsc_agent_ticket_list_status', '0');
63 } else {
64 add_term_meta ($term['term_id'], 'wpsc_allow_ticket_list', '0');
65 }
66
67 if ($field_types[$field_type]['allow_ticket_filter']) {
68 add_term_meta ($term['term_id'], 'wpsc_allow_ticket_filter', '1');
69 add_term_meta ($term['term_id'], 'wpsc_ticket_filter_type', $field_types[$field_type]['ticket_filter_type']);
70 add_term_meta ($term['term_id'], 'wpsc_customer_ticket_filter_status', '0');
71 add_term_meta ($term['term_id'], 'wpsc_agent_ticket_filter_status', '0');
72 } else {
73 add_term_meta ($term['term_id'], 'wpsc_allow_ticket_filter', '0');
74 }
75
76 if ($field_types[$field_type]['allow_orderby']) {
77 add_term_meta ($term['term_id'], 'wpsc_allow_orderby', '1');
78 } else {
79 add_term_meta ($term['term_id'], 'wpsc_allow_orderby', '0');
80 }
81
82 $check_str = $wpscfunction->check_str_is_non_english($field_label);
83 if(!$check_str){
84 wp_update_term($term['term_id'],'wpsc_ticket_custom_fields',array('slug' => 'cust_'.$term['term_id']));
85 }
86
87 $custom_fields_localize = get_option('wpsc_custom_fields_localize');
88 if (!$custom_fields_localize) {
89 $custom_fields_localize = array();
90 }
91 $custom_fields_localize['custom_fields_' . $term['term_id']] = $field_label;
92 update_option('wpsc_custom_fields_localize', $custom_fields_localize);
93
94 $custom_fields_extra_info = get_option('wpsc_custom_fields_extra_info');
95 if (!$custom_fields_extra_info) {
96 $custom_fields_extra_info = array();
97 }
98 $custom_fields_extra_info['custom_fields_extra_info_' . $term['term_id']] = $extra_info;
99 update_option('wpsc_custom_fields_extra_info', $custom_fields_extra_info);
100
101 do_action('wpsc_set_add_agentonly_field',$term['term_id']);
102 echo '{ "sucess_status":"1","messege":"'.__('Field added successfully.','supportcandy').'" }';
103 } else {
104 echo '{ "sucess_status":"0","messege":"'.__('An error occured while creating custom field.','supportcandy').'" }';
105 }
106