← All changes
|
integrations/fluent-support/includes/triggers/agent-open-ticket.php
+80
-0
5.7.2
→
6.0.3
View file →
| @@ -1,0 +1,80 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Agent Open Ticket | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\Integrations\Fluent_Support\Triggers\Agent_Open_Ticket | |
| 6 | + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]> | |
| 7 | + * @since 1.0.0 | |
| 8 | + */ | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +class AutomatorWP_Fluent_Support_Agent_Open_Ticket extends AutomatorWP_Integration_Trigger { | |
| 13 | + | |
| 14 | + public $integration = 'fluent_support'; | |
| 15 | + public $trigger = 'fluent_support_agent_open_ticket'; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Register the trigger | |
| 19 | + * | |
| 20 | + * @since 1.0.0 | |
| 21 | + */ | |
| 22 | + public function register() { | |
| 23 | + | |
| 24 | + automatorwp_register_trigger( $this->trigger, array( | |
| 25 | + 'integration' => $this->integration, | |
| 26 | + 'label' => __( 'Agent opens a ticket', 'automatorwp' ), | |
| 27 | + 'select_option' => __( 'Agent <strong>opens</strong> a ticket', 'automatorwp' ), | |
| 28 | + /* translators: %1$s: Number of times. */ | |
| 29 | + 'edit_label' => sprintf( __( 'Agent opens a ticket %1$s time(s)', 'automatorwp' ), '{times}' ), | |
| 30 | + 'log_label' => __( 'Agent opens a ticket', 'automatorwp' ), | |
| 31 | + 'action' => 'fluent_support/ticket_created', | |
| 32 | + 'function' => array( $this, 'listener' ), | |
| 33 | + 'priority' => 10, | |
| 34 | + 'accepted_args' => 1, | |
| 35 | + 'options' => array( | |
| 36 | + 'times' => automatorwp_utilities_times_option() | |
| 37 | + ), | |
| 38 | + 'tags' => array( | |
| 39 | + automatorwp_utilities_post_tags( __( 'Ticket', 'automatorwp' ) ), | |
| 40 | + 'times' => automatorwp_utilities_times_tag( true ) | |
| 41 | + ) | |
| 42 | + ) ); | |
| 43 | + | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Trigger listener | |
| 48 | + * | |
| 49 | + * @since 1.0.0 | |
| 50 | + * | |
| 51 | + * @param array $ticket Data opened ticket | |
| 52 | + */ | |
| 53 | + public function listener( $ticket ) { | |
| 54 | + global $wpdb; | |
| 55 | + | |
| 56 | + $ticket_id = absint( $ticket['id'] ); | |
| 57 | + $user = wp_get_current_user(); | |
| 58 | + | |
| 59 | + $agent = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fs_persons WHERE email='{$user->user_email}'" ); | |
| 60 | + | |
| 61 | + // Bail if agent not found | |
| 62 | + if( ! $agent ) { | |
| 63 | + return; | |
| 64 | + } | |
| 65 | + | |
| 66 | + // Bail if person entry is not an agent | |
| 67 | + if ( $agent->person_type !== 'agent' ){ | |
| 68 | + return; | |
| 69 | + } | |
| 70 | + | |
| 71 | + automatorwp_trigger_event( array( | |
| 72 | + 'trigger' => $this->trigger, | |
| 73 | + 'post_id' => $ticket_id, | |
| 74 | + 'user_id' => $user->ID, | |
| 75 | + ) ); | |
| 76 | + } | |
| 77 | + | |
| 78 | +} | |
| 79 | + | |
| 80 | +new AutomatorWP_Fluent_Support_Agent_Open_Ticket(); | |