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

class-wpsc-triggers.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.4, at includes/class-wpsc-triggers.php

111 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 if ( ! class_exists( 'WPSC_Triggers' ) ) :
7
8 final class WPSC_Triggers {
9
10 /**
11 * Published triggers
12 *
13 * @var array
14 */
15 public static $triggers = array();
16
17 /**
18 * Initialize this class
19 *
20 * @return void
21 */
22 public static function init() {
23
24 add_action( 'init', array( __CLASS__, 'load_triggers' ) );
25 }
26
27 /**
28 * Load triggers
29 *
30 * @return void
31 */
32 public static function load_triggers() {
33
34 self::$triggers = apply_filters(
35 'wpsc_triggers',
36 array(
37 'create-ticket' => esc_attr__( 'Create new ticket', 'supportcandy' ),
38 'reply-ticket' => esc_attr__( 'Ticket reply', 'supportcandy' ),
39 'submit-note' => esc_attr__( 'Submit private note', 'supportcandy' ),
40 'change-ticket-subject' => esc_attr__( 'Change ticket subject', 'supportcandy' ),
41 'change-ticket-status' => esc_attr__( 'Change ticket status', 'supportcandy' ),
42 'change-ticket-category' => esc_attr__( 'Change ticket category', 'supportcandy' ),
43 'change-ticket-priority' => esc_attr__( 'Change ticket priority', 'supportcandy' ),
44 'change-assignee' => esc_attr__( 'Change assignee', 'supportcandy' ),
45 'change-ticket-fields' => esc_attr__( 'Change ticket fields', 'supportcandy' ),
46 'change-agentonly-fields' => esc_attr__( 'Change agentonly fields', 'supportcandy' ),
47 'delete-ticket' => esc_attr__( 'Delete ticket', 'supportcandy' ),
48 )
49 );
50 }
51
52 /**
53 * Print trigger input field
54 *
55 * @param string $name - form element name.
56 * @param string $hook - hook for filtering the triggers.
57 * @param string $value - pre-set value.
58 * @param boolean $is_required - set whether or not to print required character.
59 * @param string $label - form element label.
60 * @param boolean $is_disabled - sometimes triggers can not be changed in an edit form e.g. ticket notifications. So, we just show disabled dropdown with pre-set value.
61 * @return void
62 */
63 public static function print( $name, $hook, $value = '', $is_required = false, $label = '', $is_disabled = false ) {
64
65 $label = $label ? $label : __( 'Trigger', 'supportcandy' );
66 $triggers = apply_filters( $hook, self::$triggers );
67 ?>
68 <div class="wpsc-input-group">
69 <div class="label-container">
70 <label for="">
71 <?php
72 echo esc_html( $label );
73 if ( $is_required ) {
74 ?>
75 <span class="required-char">*</span>
76 <?php
77 }
78 ?>
79 </label>
80 </div>
81 <select name="<?php echo esc_html( $name ); ?>" <?php echo $is_disabled ? 'disabled' : ''; ?>>
82 <?php
83 foreach ( $triggers as $key => $val ) {
84 ?>
85 <option <?php selected( $value, $key, true ); ?> value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $val ); ?></option>
86 <?php
87 }
88 ?>
89 </select>
90 </div>
91 <?php
92 }
93
94 /**
95 * Check whether or not trigger value is valid or not
96 *
97 * @param string $hook - hook for filtering the triggers.
98 * @param string $value - value to check valid or not.
99 * @return boolean
100 */
101 public static function is_valid( $hook, $value ) {
102
103 $triggers = apply_filters( $hook, self::$triggers );
104 return isset( $triggers[ $value ] );
105 }
106 }
107
108 endif;
109
110 WPSC_Triggers::init();
111