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

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

166 lines 4.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
69 <div class="wpsc-setting-header">
70 <h2><?php esc_attr_e( 'Customer Fields', 'supportcandy' ); ?></h2>
71 </div>
72 <div class="wpsc-setting-section-body">
73 <div class="wpsc-dock-container">
74 <?php
75 printf(
76 /* translators: Click here to see the documentation */
77 esc_attr__( '%s to see the documentation!', 'supportcandy' ),
78 '<a href="https://supportcandy.net/docs/customer-fields/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>'
79 );
80 ?>
81 </div>
82 <table class="ticket-fields wpsc-setting-tbl">
83 <thead>
84 <tr>
85 <th><?php esc_attr_e( 'Field', 'supportcandy' ); ?></th>
86 <th><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></th>
87 <th><?php esc_attr_e( 'Actions', 'supportcandy' ); ?></th>
88 </tr>
89 </thead>
90 <tbody>
91 <?php
92 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
93 if ( $cf->field != 'customer' ) {
94 continue;
95 }
96 ?>
97 <tr>
98 <td><?php echo esc_attr( $cf->name ); ?></td>
99 <td><?php echo esc_attr( $cf->extra_info ); ?></td>
100 <td>
101 <a href="javascript:wpsc_get_edit_custom_field(<?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_edit_custom_field' ) ); ?>');" class="wpsc-link"><?php esc_attr_e( 'Edit', 'supportcandy' ); ?></a>
102 <?php
103 if ( ! $cf->type::$is_default ) {
104 echo esc_attr( ' | ' );
105 ?>
106 <a href="javascript:wpsc_delete_custom_field(<?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_delete_custom_field' ) ); ?>');" class="wpsc-link"><?php esc_attr_e( 'Delete', 'supportcandy' ); ?></a>
107 <?php
108 }
109 ?>
110 </td>
111 </tr>
112 <?php
113 }
114 ?>
115 </tbody>
116 </table>
117 <script>
118 jQuery('table.ticket-fields').DataTable({
119 ordering: false,
120 pageLength: 20,
121 bLengthChange: false,
122 columnDefs: [
123 { targets: -1, searchable: false },
124 { targets: '_all', className: 'dt-left' }
125 ],
126 layout: {
127 topStart: {
128 buttons: [
129 {
130 text: '<?php esc_attr_e( 'Add new', 'supportcandy' ); ?>',
131 className: 'wpsc-button small primary',
132 action: function ( e, dt, node, config ) {
133 wpsc_get_add_new_custom_field('customer', '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_add_new_custom_field' ) ); ?>');
134 }
135 }
136 ],
137 },
138 },
139 language: supportcandy.translations.datatables
140 });
141 </script>
142 </div>
143 <?php
144 wp_die();
145 }
146
147 /**
148 * Filter out unwanted custom field types from add new custom field section for customer fields
149 *
150 * @param array $cf_types - cf_types.
151 * @param string $field - custom field category (ticket, agentonly, customer, etc.).
152 * @return array
153 */
154 public static function filter_cf_types( $cf_types, $field ) {
155
156 if ( $field == 'customer' && in_array( 'cf_html', array_keys( $cf_types ) ) ) {
157 unset( $cf_types['cf_html'] );
158 }
159
160 return $cf_types;
161 }
162 }
163 endif;
164
165 WPSC_CF::init();
166