PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 5.8.5
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v5.8.5
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / integrations / fluentbooking / includes / triggers / user-single-schedule-meeting.php

user-single-schedule-meeting.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 5.8.5, at integrations/fluentbooking/includes/triggers/user-single-schedule-meeting.php

166 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Schedule Meeting
4 *
5 * @package AutomatorWP\Integrations\FluentBooking\Triggers\Schedule_Meeting
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_FluentBooking_Schedule_Meeting extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'fluentbooking';
15 public $trigger = 'fluentbooking_schedule_meeting';
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' => __( 'User schedules one-to-one meeting', 'automatorwp' ),
27 'select_option' => __( 'User schedules one-to-one <strong>a meeting</strong>', 'automatorwp' ),
28 /* translators: %1$s: Meeting title. %2$s: Number of times. */
29 'edit_label' => sprintf( __( 'User schedules one-to-one %1$s %2$s time(s)', 'automatorwp' ), '{post}', '{times}' ),
30 /* translators: %1$s: Meeting title. */
31 'log_label' => sprintf( __( 'User schedules one-to-one %1$s', 'automatorwp' ), '{post}' ),
32 'action' => 'fluent_booking/after_booking_scheduled',
33 'function' => array( $this, 'listener' ),
34 'priority' => 10,
35 'accepted_args' => 3,
36 'options' => array(
37 'post' => automatorwp_utilities_ajax_selector_option( array(
38 'field' => 'post',
39 'name' => __( 'Meeting:', 'automatorwp' ),
40 'option_none_value' => 'any',
41 'option_none_label' => __( 'any meeting', 'automatorwp' ),
42 'action_cb' => 'automatorwp_fluentbooking_get_single_events',
43 'options_cb' => 'automatorwp_fluentbooking_options_cb_single_event',
44 'default' => 'any'
45 ) ),
46 'times' => automatorwp_utilities_times_option(),
47 ),
48 'tags' => array_merge(
49 automatorwp_fluentbooking_get_event_tags(),
50 automatorwp_utilities_times_tag()
51 )
52 ) );
53
54 }
55
56 /**
57 * Trigger listener
58 *
59 * @since 1.0.0
60 *
61 * @param FluentBooking\App\Models\Booking $booking
62 * @param FluentBooking\App\Models\CalendarSlot $calendarSlot
63 * @param array $bookingData
64 */
65 public function listener( $booking, $calendarSlot, $bookingData ) {
66
67 $user_id = get_current_user_id();
68
69 // Login is required
70 if ( $user_id === 0 ) {
71 return;
72 }
73
74 $event_type = $booking->getAttribute( 'event_type' );
75
76 // Bail if not one-to-one event
77 if ( $event_type !== 'single' && $event_type !== 'group' ) {
78 return;
79 }
80
81 $booking_id = $booking->getAttribute( 'id' );
82 $event_id = $booking->getAttribute( 'event_id' );
83
84 // Trigger one-to-one schedule meeting
85 automatorwp_trigger_event( array(
86 'trigger' => $this->trigger,
87 'user_id' => $user_id,
88 'event_id' => $event_id,
89 'booking_id' => $booking_id,
90 ) );
91
92 }
93
94 /**
95 * User deserves check
96 *
97 * @since 1.0.0
98 *
99 * @param bool $deserves_trigger True if user deserves trigger, false otherwise
100 * @param stdClass $trigger The trigger object
101 * @param int $user_id The user ID
102 * @param array $event Event information
103 * @param array $trigger_options The trigger's stored options
104 * @param stdClass $automation The trigger's automation object
105 *
106 * @return bool True if user deserves trigger, false otherwise
107 */
108 public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
109
110 // Don't deserve if post is not received
111 if( ! isset( $event['event_id'] ) ) {
112 return false;
113 }
114
115 // Bail if post doesn't match with the trigger option
116 if( $trigger_options['post'] !== 'any' && absint( $event['event_id'] ) !== absint( $trigger_options['post'] ) ) {
117 return false;
118 }
119
120 return $deserves_trigger;
121
122 }
123
124 /**
125 * Register the required hooks
126 *
127 * @since 1.0.0
128 */
129 public function hooks() {
130
131 // Log meta data
132 add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
133
134 parent::hooks();
135 }
136
137 /**
138 * Trigger custom log meta
139 *
140 * @since 1.0.0
141 *
142 * @param array $log_meta Log meta data
143 * @param stdClass $trigger The trigger object
144 * @param int $user_id The user ID
145 * @param array $event Event information
146 * @param array $trigger_options The trigger's stored options
147 * @param stdClass $automation The trigger's automation object
148 *
149 * @return array
150 */
151 function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
152
153 // Bail if action type don't match this action
154 if( $trigger->type !== $this->trigger ) {
155 return $log_meta;
156 }
157
158 $log_meta['booking_id'] = ( isset( $event['booking_id'] ) ? $event['booking_id'] : '' );
159
160 return $log_meta;
161
162 }
163
164 }
165
166 new AutomatorWP_FluentBooking_Schedule_Meeting();