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 / rest_api / v1 / get_ticket_form_fields.php

get_ticket_form_fields.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 2.3.1, at includes/rest_api/v1/get_ticket_form_fields.php

105 lines 3.3 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 global $current_user;
7
8 $response = array();
9
10 $ticket_form_fields = get_terms([
11 'taxonomy' => 'wpsc_ticket_custom_fields',
12 'hide_empty' => false,
13 'orderby' => 'meta_value_num',
14 'meta_key' => 'wpsc_tf_load_order',
15 'order' => 'ASC',
16 'meta_query' => array(
17 array(
18 'key' => 'agentonly',
19 'value' => '0',
20 'compare' => '='
21 )
22 ),
23 ]);
24
25 foreach ( $ticket_form_fields as $form_field ) {
26
27 if ( $current_user->ID && ( $form_field->slug == 'customer_name' || $form_field->slug == 'customer_email' ) ) {
28 continue;
29 }
30
31 $visibility = get_term_meta( $form_field->term_id, 'wpsc_tf_visibility', true);
32 $visibility = is_array($visibility) ? $visibility : array();
33 $visibility_conditions = array();
34 foreach ($visibility as $condition) {
35 $condition = explode('--', $condition);
36 $visibility_conditions[] = array(
37 'field_id' => $condition[0],
38 'value' => $condition[1],
39 );
40 }
41
42 $options = get_term_meta( $form_field->term_id, 'wpsc_tf_options', true);
43 $options = is_array($options) ? $options : array();
44 $options = isset($options[0]) && $options[0] ? $options : array();
45
46 $temp_options = array();
47 foreach ($options as $value) {
48 $temp_options[] = array(
49 'name' => $value,
50 'value' => $value
51 );
52 }
53 $options = $temp_options;
54
55 if( $form_field->slug == 'ticket_priority' ) {
56 $priorities = get_terms([
57 'taxonomy' => 'wpsc_priorities',
58 'hide_empty' => false,
59 'orderby' => 'meta_value_num',
60 'order' => 'ASC',
61 'meta_query' => array('order_clause' => array('key' => 'wpsc_priority_load_order')),
62 ]);
63 foreach ( $priorities as $priority ) {
64 $options[] = array(
65 'name' => $priority->name,
66 'value' => $priority->term_id
67 );
68 }
69 }
70
71 if( $form_field->slug == 'ticket_category' ) {
72 $categories = get_terms([
73 'taxonomy' => 'wpsc_categories',
74 'hide_empty' => false,
75 'orderby' => 'meta_value_num',
76 'order' => 'ASC',
77 'meta_query' => array('order_clause' => array('key' => 'wpsc_category_load_order')),
78 ]);
79 foreach ( $categories as $category ) {
80 $options[] = array(
81 'name' => $category->name,
82 'value' => $category->term_id
83 );
84 }
85 }
86
87 $field = array(
88 'id' => $form_field->term_id,
89 'slug' => $form_field->slug,
90 'label' => get_term_meta( $form_field->term_id, 'wpsc_tf_label', true),
91 'extra_info' => get_term_meta( $form_field->term_id, 'wpsc_tf_extra_info', true),
92 'type' => get_term_meta( $form_field->term_id, 'wpsc_tf_type', true),
93 'options' => $options,
94 'default_visibility' => get_term_meta( $form_field->term_id, 'wpsc_tf_status', true),
95 'required' => get_term_meta( $form_field->term_id, 'wpsc_tf_required', true),
96 'width' => get_term_meta( $form_field->term_id, 'wpsc_tf_width', true),
97 'visibility_conditions' => $visibility_conditions,
98 );
99
100 $field = apply_filters('wpsc_api_v1_ticket_form_fields',$field);
101
102 $response[] = $field;
103
104 }
105