PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.8
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.8
8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 7.8.7 All 46 releases
gamipress / integrations / bookingcalendar / includes / triggers.php

triggers.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.8, at integrations/bookingcalendar/includes/triggers.php

188 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Triggers
4 *
5 * @package GamiPress\BookingCalendar\Triggers
6 * @since 1.0.0
7 */
8
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Register plugin specific triggers
14 *
15 * @since 1.0.0
16 *
17 * @param array $triggers
18 * @return mixed
19 */
20 function gamipress_bookingcalendar_activity_triggers( $triggers ) {
21
22 $triggers[__( 'WP Booking Calendar', 'gamipress' )] = array(
23 'gamipress_bookingcalendar_new_booking_scheduled' => __( 'New booking scheduled', 'gamipress' ),
24 'gamipress_bookingcalendar_booking_approved' => __( 'Booking is set to approved', 'gamipress' ),
25 'gamipress_bookingcalendar_specific_booking_approved' => __( 'Specific booking is set to approved', 'gamipress' ),
26 'gamipress_bookingcalendar_booking_pending' => __( 'Booking is set to pending', 'gamipress' ),
27 'gamipress_bookingcalendar_specific_booking_pending' => __( 'Specific booking is set to pending', 'gamipress' ),
28 'gamipress_bookingcalendar_booking_cancelled' => __( 'Booking is set to cancelled', 'gamipress' ),
29 'gamipress_bookingcalendar_specific_booking_cancelled' => __( 'Specific booking is set to cancelled', 'gamipress' ),
30 );
31
32 return $triggers;
33
34 }
35 add_filter( 'gamipress_activity_triggers', 'gamipress_bookingcalendar_activity_triggers' );
36
37 /**
38 * Register plugin specific activity triggers
39 *
40 * @since 1.0.0
41 *
42 * @param array $specific_activity_triggers
43 * @return array
44 */
45 function gamipress_bookingcalendar_specific_activity_triggers( $specific_activity_triggers ) {
46
47 $specific_activity_triggers['gamipress_bookingcalendar_specific_booking_approved'] = array( 'booking' );
48 $specific_activity_triggers['gamipress_bookingcalendar_specific_booking_pending'] = array( 'booking' );
49 $specific_activity_triggers['gamipress_bookingcalendar_specific_booking_cancelled'] = array( 'booking' );
50
51 return $specific_activity_triggers;
52 }
53 add_filter( 'gamipress_specific_activity_triggers', 'gamipress_bookingcalendar_specific_activity_triggers' );
54
55 /**
56 * Register plugin specific activity triggers labels
57 *
58 * @since 1.0.0
59 *
60 * @param array $specific_activity_trigger_labels
61 * @return array
62 */
63 function gamipress_bookingcalendar_specific_activity_trigger_label( $specific_activity_trigger_labels ) {
64
65 $specific_activity_trigger_labels['gamipress_bookingcalendar_specific_booking_approved'] = __( '%s set to approved', 'gamipress' );
66 $specific_activity_trigger_labels['gamipress_bookingcalendar_specific_booking_pending'] = __( '%s set to pending', 'gamipress' );
67 $specific_activity_trigger_labels['gamipress_bookingcalendar_specific_booking_cancelled'] = __( '%s set to cancelled', 'gamipress' );
68
69 return $specific_activity_trigger_labels;
70 }
71 add_filter( 'gamipress_specific_activity_trigger_label', 'gamipress_bookingcalendar_specific_activity_trigger_label' );
72
73 /**
74 * Get plugin specific activity trigger post title
75 *
76 * @since 1.0.0
77 *
78 * @param string $post_title
79 * @param integer $specific_id
80 * @param string $trigger_type
81 * @return string
82 */
83 function gamipress_bookingcalendar_specific_activity_trigger_post_title( $post_title, $specific_id, $trigger_type ) {
84
85 global $wpdb;
86
87 switch( $trigger_type ) {
88 case 'gamipress_bookingcalendar_specific_booking_approved':
89 case 'gamipress_bookingcalendar_specific_booking_pending':
90 case 'gamipress_bookingcalendar_specific_booking_cancelled':
91 if( absint( $specific_id ) !== 0 ) {
92 $site_bookings = $wpdb->get_results( $wpdb->prepare(
93 "SELECT booking_id, sort_date FROM {$wpdb->prefix}booking WHERE booking_id LIKE $specific_id",
94 "%{$search}%"
95 ) );
96
97 foreach ( $site_bookings as $booking ) {
98 $post_title = 'Booking ' . $booking->booking_id . ': ' . $booking->sort_date;
99 }
100 }
101 break;
102 }
103
104 return $post_title;
105
106 }
107 add_filter( 'gamipress_specific_activity_trigger_post_title', 'gamipress_bookingcalendar_specific_activity_trigger_post_title', 10, 3 );
108
109 /**
110 * Get user for a given trigger action.
111 *
112 * @since 1.0.0
113 *
114 * @param integer $user_id user ID to override.
115 * @param string $trigger Trigger name.
116 * @param array $args Passed trigger args.
117 * @return integer User ID.
118 */
119 function gamipress_bookingcalendar_trigger_get_user_id( $user_id, $trigger, $args ) {
120
121 switch ($trigger) {
122 case 'gamipress_bookingcalendar_new_booking_scheduled':
123 case 'gamipress_bookingcalendar_booking_approved':
124 case 'gamipress_bookingcalendar_specific_booking_approved':
125 case 'gamipress_bookingcalendar_booking_pending':
126 case 'gamipress_bookingcalendar_specific_booking_pending':
127 case 'gamipress_bookingcalendar_booking_cancelled':
128 case 'gamipress_bookingcalendar_specific_booking_cancelled':
129 $user_id = $args[1];
130 break;
131 }
132
133 return $user_id;
134 }
135 add_filter( 'gamipress_trigger_get_user_id', 'gamipress_bookingcalendar_trigger_get_user_id', 10, 3 );
136
137 /**
138 * Get the id for a given specific trigger action.
139 *
140 * @since 1.0.0
141 *
142 * @param integer $specific_id Specific ID.
143 * @param string $trigger Trigger name.
144 * @param array $args Passed trigger args.
145 *
146 * @return integer Specific ID.
147 */
148 function gamipress_bookingcalendar_specific_trigger_get_id( $specific_id, $trigger = '', $args = array() ) {
149
150 switch( $trigger ) {
151 case 'gamipress_bookingcalendar_specific_booking_approved':
152 case 'gamipress_bookingcalendar_specific_booking_pending':
153 case 'gamipress_bookingcalendar_specific_booking_cancelled':
154 $specific_id = $args[0];
155 break;
156 }
157
158 return $specific_id;
159 }
160 add_filter( 'gamipress_specific_trigger_get_id', 'gamipress_bookingcalendar_specific_trigger_get_id', 10, 3 );
161
162 /**
163 * Extended meta data for event trigger logging
164 *
165 * @since 1.0.0
166 *
167 * @param array $log_meta
168 * @param integer $user_id
169 * @param string $trigger
170 * @param integer $site_id
171 * @param array $args
172 *
173 * @return array
174 */
175 function gamipress_bookingcalendar_log_event_trigger_meta_data( $log_meta, $user_id, $trigger, $site_id, $args ) {
176
177 switch( $trigger ) {
178 case 'gamipress_bookingcalendar_specific_booking_approved':
179 case 'gamipress_bookingcalendar_specific_booking_pending':
180 case 'gamipress_bookingcalendar_specific_booking_cancelled':
181 // Add the booking ID
182 $log_meta['booking_id'] = $args[0];
183 break;
184 }
185
186 return $log_meta;
187 }
188 add_filter( 'gamipress_log_event_trigger_meta_data', 'gamipress_bookingcalendar_log_event_trigger_meta_data', 10, 5 );