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 / tickets / class-wpsc-ticket-restrictions-manager.php

class-wpsc-ticket-restrictions-manager.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.4.4, at includes/admin/tickets/class-wpsc-ticket-restrictions-manager.php

105 lines 3.0 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_Ticket_Restrictions_Manager' ) ) :
7
8 final class WPSC_Ticket_Restrictions_Manager {
9
10 /**
11 * Initialize the class
12 *
13 * @return void
14 */
15 public static function init() {
16
17 add_filter( 'wpsc_individual_ticket_actions', array( __CLASS__, 'individual_ticket_actions' ), 10, 2 );
18 add_filter( 'wpsc_it_submit_actions', array( __CLASS__, 'it_submit_actions' ), 99, 2 );
19 add_filter( 'wpsc_it_thread_actions', array( __CLASS__, 'it_thread_actions' ), 10, 2 );
20 }
21
22 /**
23 * Check if a ticket action is restricted.
24 *
25 * @param WPSC_Ticket $ticket Ticket object.
26 * @param string $action Name of action like reply, delete, note, etc.
27 * @return bool
28 */
29 public static function is_restricted( $ticket, $action = '' ) {
30
31 // If ticket is active, restriction ALWAYS true.
32 if ( ! $ticket->is_active ) {
33 return true;
34 }
35
36 // If active, let filter decide.
37 $restricted = apply_filters( 'wpsc_restricted_ticket_action', false, $ticket, $action );
38
39 return $restricted;
40 }
41
42 /**
43 * Filter ticket actions based on ticket status.
44 *
45 * @param array $actions - action array.
46 * @param WPSC_Ticket $ticket - ticket object.
47 * @return array
48 */
49 public static function individual_ticket_actions( $actions, $ticket ) {
50
51 if ( ! $ticket->is_active ) {
52 $restricted = array( 'refresh', 'close', 'duplicate', 'copy', 'archive', 'delete' );
53 } else {
54 $restricted = array( 'restore', 'delete-permanently' );
55 }
56
57 $allows_actions = array_diff_key( $actions, array_flip( $restricted ) );
58 $allows_actions = apply_filters( 'wpsc_allowed_it_actions', $allows_actions, $actions, $ticket );
59 return $allows_actions;
60 }
61
62 /**
63 * Filter submit actions based on ticket status.
64 *
65 * @param array $actions - action array.
66 * @param WPSC_Ticket $ticket - ticket object.
67 * @return array
68 */
69 public static function it_submit_actions( $actions, $ticket ) {
70
71 if ( ! $ticket->is_active ) {
72 $restricted = array( 'reply', 'private-note', 'reply-and-close' );
73 } else {
74 $restricted = array();
75 }
76
77 $allows_actions = array_diff_key( $actions, array_flip( $restricted ) );
78 $allows_actions = apply_filters( 'wpsc_allowed_it_aubmit_actions', $allows_actions, $actions, $ticket );
79 return $allows_actions;
80 }
81
82 /**
83 * Filter submit actions based on ticket status.
84 *
85 * @param array $actions - action array.
86 * @param WPSC_Ticket $ticket - ticket object.
87 * @return array
88 */
89 public static function it_thread_actions( $actions, $ticket ) {
90
91 if ( ! $ticket->is_active ) {
92 $restricted = array( 'edit', 'delete' );
93 } else {
94 $restricted = array();
95 }
96
97 $allows_actions = array_diff_key( $actions, array_flip( $restricted ) );
98 $allows_actions = apply_filters( 'wpsc_allowed_it_thread_actions', $allows_actions, $actions, $ticket );
99 return $allows_actions;
100 }
101 }
102
103 endif;
104 WPSC_Ticket_Restrictions_Manager::init();
105