PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.7
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.7
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 / class-wpsc-cf.php

class-wpsc-cf.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.4.7, at includes/admin/custom-fields/class-wpsc-cf.php

178 lines 5.5 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 ( ! class_exists( 'WPSC_CF' ) ) :
7
8 final class WPSC_CF {
9
10 /**
11 * Allowed custom field properties
12 *
13 * @var array
14 */
15 public static $allowed_properties = array(
16 'extra_info',
17 'placeholder_text',
18 'char_limit',
19 'date_format',
20 'date_range',
21 'start_range',
22 'end_range',
23 'time_format',
24 'tl_width',
25 'allow_ticket_form',
26 'allow_my_profile',
27 'is_personal_info',
28 'number_type',
29 );
30
31 /**
32 * Initialize this class
33 */
34 public static function init() {
35
36 // Register this field category (ticket).
37 add_filter( 'wpsc_custom_field_categories', array( __CLASS__, 'register_field' ) );
38
39 // List.
40 add_action( 'wp_ajax_wpsc_get_customer_fields', array( __CLASS__, 'get_customer_fields' ) );
41
42 // Filter custom field types for new custom field.
43 add_filter( 'wpsc_add_new_custom_field_cf_types', array( __CLASS__, 'filter_cf_types' ), 10, 2 );
44 }
45
46 /**
47 * Register field category
48 *
49 * @param array $fields - customer fields.
50 * @return array
51 */
52 public static function register_field( $fields ) {
53
54 $fields['customer'] = __CLASS__;
55 return $fields;
56 }
57
58 /**
59 * Get customer fields
60 *
61 * @return void
62 */
63 public static function get_customer_fields() {
64
65 if ( ! WPSC_Functions::is_site_admin() ) {
66 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
67 }
68 $custom_fields_types = array_merge( WPSC_Custom_Field::$cf_types, WPSC_Custom_Field::$default_cf_types );
69 ?>
70
71 <div class="wpsc-setting-header">
72 <h2><?php esc_attr_e( 'Customer Fields', 'supportcandy' ); ?></h2>
73 </div>
74 <div class="wpsc-setting-section-body">
75 <div class="wpsc-dock-container">
76 <?php
77 printf(
78 /* translators: Click here to see the documentation */
79 esc_attr__( '%s to see the documentation!', 'supportcandy' ),
80 '<a href="https://supportcandy.net/docs/customer-fields/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>'
81 );
82 ?>
83 </div>
84 <table class="ticket-fields wpsc-setting-tbl">
85 <thead>
86 <tr>
87 <th><?php esc_attr_e( 'Field', 'supportcandy' ); ?></th>
88 <th><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></th>
89 <th><?php esc_attr_e( 'Type', 'supportcandy' ); ?></th>
90 <th><?php esc_attr_e( 'Auto Fill', 'supportcandy' ); ?></th>
91 <th><?php esc_attr_e( 'Personal Info', 'supportcandy' ); ?></th>
92 <th><?php esc_attr_e( 'Allow in My Profile', 'supportcandy' ); ?></th>
93 <th><?php esc_attr_e( 'Allow in Ticket Form', 'supportcandy' ); ?></th>
94 <th><?php esc_attr_e( 'Actions', 'supportcandy' ); ?></th>
95 </tr>
96 </thead>
97 <tbody>
98 <?php
99 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
100 if ( $cf->field != 'customer' ) {
101 continue;
102 }
103 ?>
104 <tr>
105 <td><?php echo esc_attr( $cf->name ); ?></td>
106 <td><?php echo esc_attr( $cf->extra_info ); ?></td>
107 <td><?php echo esc_attr( $custom_fields_types[ $cf->type::$slug ]['label'] ); ?></td>
108 <td><?php echo esc_attr( $cf->is_auto_fill ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ) ); ?></td>
109 <td><?php echo esc_attr( $cf->is_personal_info ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ) ); ?></td>
110 <td><?php echo esc_attr( $cf->allow_my_profile ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ) ); ?></td>
111 <td><?php echo esc_attr( $cf->allow_ticket_form ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ) ); ?></td>
112 <td>
113 <span class="wpsc-link" onclick="wpsc_get_edit_custom_field(<?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_edit_custom_field' ) ); ?>');"><?php esc_attr_e( 'Edit', 'supportcandy' ); ?></span>
114 <?php
115 if ( ! $cf->type::$is_default ) {
116 echo esc_attr( ' | ' );
117 ?>
118 <span class="wpsc-link" onclick="wpsc_delete_custom_field(<?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_delete_custom_field' ) ); ?>');"><?php esc_attr_e( 'Delete', 'supportcandy' ); ?></span>
119 <?php
120 }
121 ?>
122 </td>
123 </tr>
124 <?php
125 }
126 ?>
127 </tbody>
128 </table>
129 <script>
130 jQuery('table.ticket-fields').DataTable({
131 ordering: false,
132 pageLength: 20,
133 bLengthChange: false,
134 columnDefs: [
135 { targets: -1, searchable: false },
136 { targets: '_all', className: 'dt-left' }
137 ],
138 layout: {
139 topStart: {
140 buttons: [
141 {
142 text: '<?php esc_attr_e( 'Add new', 'supportcandy' ); ?>',
143 className: 'wpsc-button small primary',
144 action: function ( e, dt, node, config ) {
145 wpsc_get_add_new_custom_field('customer', '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_add_new_custom_field' ) ); ?>');
146 }
147 }
148 ],
149 },
150 },
151 language: supportcandy.translations.datatables
152 });
153 </script>
154 </div>
155 <?php
156 wp_die();
157 }
158
159 /**
160 * Filter out unwanted custom field types from add new custom field section for customer fields
161 *
162 * @param array $cf_types - cf_types.
163 * @param string $field - custom field category (ticket, agentonly, customer, etc.).
164 * @return array
165 */
166 public static function filter_cf_types( $cf_types, $field ) {
167
168 if ( $field == 'customer' && in_array( 'cf_html', array_keys( $cf_types ) ) ) {
169 unset( $cf_types['cf_html'] );
170 }
171
172 return $cf_types;
173 }
174 }
175 endif;
176
177 WPSC_CF::init();
178