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

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

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