PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / trunk
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent vtrunk
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 / onboarding / class-wpsc-onboarding-step-fields.php

class-wpsc-onboarding-step-fields.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent trunk, at includes/admin/onboarding/class-wpsc-onboarding-step-fields.php

139 lines 4.7 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_Onboarding_Step_Fields' ) ) :
7
8 /**
9 * Onboarding step 5: Ticket Fields & Ticket Form.
10 *
11 * Purely educational - data-driven throughout, but with no links out to
12 * Settings: every other SupportCandy submenu is hidden while setup is
13 * pending (see WPSC_Onboarding::restrict_menu_during_setup()), so those
14 * pages aren't reachable until the wizard is completed. Each
15 * field-type card previews the real field names on this site (via
16 * WPSC_Custom_Field::$custom_fields, already loaded for every request), and
17 * the Ticket Form section lists the real fields currently on the
18 * customer-facing new-ticket form (option 'wpsc-tff', keyed by field slug).
19 * No field data is edited here - this step is a map, not a form.
20 */
21 final class WPSC_Onboarding_Step_Fields {
22
23 const STEP_ID = 'fields';
24
25 /**
26 * Number of example field names to preview per field-type card.
27 */
28 const PREVIEW_LIMIT = 4;
29
30 /**
31 * Render step body
32 *
33 * @param string $step_id - step id.
34 * @return void
35 */
36 public static function render( $step_id ) {
37
38 $names = array(
39 'ticket' => array(),
40 'agentonly' => array(),
41 'customer' => array(),
42 );
43 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
44 if ( isset( $names[ $cf->field ] ) ) {
45 $names[ $cf->field ][] = $cf->name;
46 }
47 }
48
49 $field_types = array(
50 'ticket-fields' => array(
51 'label' => esc_attr__( 'Ticket Fields', 'supportcandy' ),
52 'desc' => esc_attr__( 'Information specific to a ticket, such as subject, status or priority.', 'supportcandy' ),
53 'names' => $names['ticket'],
54 ),
55 'agent-only-fields' => array(
56 'label' => esc_attr__( 'Agent-only Fields', 'supportcandy' ),
57 'desc' => esc_attr__( 'Used internally by your support agents and never shown to customers.', 'supportcandy' ),
58 'names' => $names['agentonly'],
59 ),
60 'customer-fields' => array(
61 'label' => esc_attr__( 'Customer Fields', 'supportcandy' ),
62 'desc' => esc_attr__( 'Information about the customer raising the ticket.', 'supportcandy' ),
63 'names' => $names['customer'],
64 ),
65 );
66
67 $tff_names = array();
68 foreach ( array_keys( get_option( 'wpsc-tff', array() ) ) as $slug ) {
69 $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
70 if ( $cf ) {
71 $tff_names[] = $cf->name;
72 }
73 }
74 ?>
75 <div class="wpsc-onboarding-step">
76 <h2><?php esc_attr_e( 'Ticket Fields & Ticket Form', 'supportcandy' ); ?></h2>
77 <p class="wpsc-onboarding-step-desc"><?php esc_attr_e( 'SupportCandy organizes information into three kinds of fields, all already set up with sensible defaults on your site:', 'supportcandy' ); ?></p>
78
79 <div class="wpsc-onboarding-stat-grid">
80 <?php foreach ( $field_types as $field_type ) : ?>
81 <div class="wpsc-onboarding-stat-card">
82 <span class="wpsc-onboarding-stat-count"><?php echo esc_html( count( $field_type['names'] ) ); ?></span>
83 <h3><?php echo esc_html( $field_type['label'] ); ?></h3>
84 <p><?php echo esc_html( $field_type['desc'] ); ?></p>
85 <p class="wpsc-onboarding-field-preview"><?php echo esc_html( self::preview_names( $field_type['names'] ) ); ?></p>
86 </div>
87 <?php endforeach; ?>
88 </div>
89
90 <hr class="wpsc-onboarding-divider">
91
92 <h2><?php esc_attr_e( 'Ticket Form', 'supportcandy' ); ?></h2>
93 <p class="wpsc-onboarding-step-desc"><?php esc_attr_e( 'These are the fields customers currently fill in when they create a ticket - a mix of the field types above.', 'supportcandy' ); ?></p>
94
95 <?php if ( ! empty( $tff_names ) ) : ?>
96 <ul class="wpsc-onboarding-pill-list">
97 <?php foreach ( $tff_names as $name ) : ?>
98 <li><?php echo esc_html( $name ); ?></li>
99 <?php endforeach; ?>
100 </ul>
101 <?php endif; ?>
102
103 <p class="wpsc-onboarding-step-desc"><?php esc_attr_e( 'You can customize and add new fields to all of these anytime from the Ticket Form settings once setup is complete.', 'supportcandy' ); ?></p>
104
105 <?php WPSC_Onboarding::render_step_footer( $step_id ); ?>
106 </div>
107 <?php
108 wp_die();
109 }
110
111 /**
112 * Short "A, B, C +N more" preview string for a list of field names.
113 *
114 * @param array $names - field names.
115 * @return string
116 */
117 private static function preview_names( $names ) {
118
119 if ( empty( $names ) ) {
120 return '';
121 }
122
123 $shown = array_slice( $names, 0, self::PREVIEW_LIMIT );
124 $remaining = count( $names ) - count( $shown );
125 $preview = implode( ', ', $shown );
126
127 if ( $remaining > 0 ) {
128 $preview .= sprintf(
129 /* translators: %d: number of additional fields not shown in the preview */
130 esc_html__( ' +%d more', 'supportcandy' ),
131 $remaining
132 );
133 }
134
135 return $preview;
136 }
137 }
138 endif;
139