| @@ -1,0 +1,270 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Triggers | |
| 4 | + * | |
| 5 | + * @package GamiPress\BookingPress\Triggers | |
| 6 | + * @since 1.0.0 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Register plugin activity triggers | |
| 14 | + * | |
| 15 | + * @param array $triggers | |
| 16 | + * @return mixed | |
| 17 | + */ | |
| 18 | +function gamipress_bookingpress_activity_triggers( $triggers ) { | |
| 19 | + | |
| 20 | + // BookingPress | |
| 21 | + $triggers[__( 'BookingPress', 'gamipress' )] = array( | |
| 22 | + // Appointments | |
| 23 | + 'gamipress_bookingpress_user_register_customer' => __( 'Register as a customer', 'gamipress' ), | |
| 24 | + 'gamipress_bookingpress_user_books_appointment' => __( 'Book an appointment for a service', 'gamipress' ), | |
| 25 | + 'gamipress_bookingpress_user_books_appointment_service' => __( 'Book an appointment for a specific service', 'gamipress' ), | |
| 26 | + 'gamipress_bookingpress_user_approves_appointment' => __( 'Approve an appointment for a service', 'gamipress' ), | |
| 27 | + 'gamipress_bookingpress_user_approves_appointment_service' => __( 'Approve an appointment for a specific service', 'gamipress' ), | |
| 28 | + 'gamipress_bookingpress_user_rejects_appointment' => __( 'Reject an appointment for a service', 'gamipress' ), | |
| 29 | + 'gamipress_bookingpress_user_rejects_appointment_service' => __( 'Reject an appointment for for a specific service', 'gamipress' ), | |
| 30 | + 'gamipress_bookingpress_user_cancels_appointment' => __( 'Cancel an appointment for a service', 'gamipress' ), | |
| 31 | + 'gamipress_bookingpress_user_cancels_appointment_service' => __( 'Cancel an appointment for a specific service', 'gamipress' ), | |
| 32 | + 'gamipress_bookingpress_user_pending_appointment' => __( 'An appointment is set to pending for a service', 'gamipress' ), | |
| 33 | + 'gamipress_bookingpress_user_pending_appointment_service' => __( 'An appointment is set to pending for a specific service', 'gamipress' ), | |
| 34 | + | |
| 35 | + ); | |
| 36 | + | |
| 37 | + return $triggers; | |
| 38 | + | |
| 39 | +} | |
| 40 | +add_filter( 'gamipress_activity_triggers', 'gamipress_bookingpress_activity_triggers' ); | |
| 41 | + | |
| 42 | +/** | |
| 43 | + * Register specific activity triggers | |
| 44 | + * | |
| 45 | + * @since 1.0.0 | |
| 46 | + * | |
| 47 | + * @param array $specific_activity_triggers | |
| 48 | + * @return array | |
| 49 | + */ | |
| 50 | +function gamipress_bookingpress_specific_activity_triggers( $specific_activity_triggers ) { | |
| 51 | + | |
| 52 | + $specific_activity_triggers['gamipress_bookingpress_user_books_appointment_service'] = array( 'bookingpress_service' ); | |
| 53 | + $specific_activity_triggers['gamipress_bookingpress_user_approves_appointment_service'] = array( 'bookingpress_service' ); | |
| 54 | + $specific_activity_triggers['gamipress_bookingpress_user_rejects_appointment_service'] = array( 'bookingpress_service' ); | |
| 55 | + $specific_activity_triggers['gamipress_bookingpress_user_cancels_appointment_service'] = array( 'bookingpress_service' ); | |
| 56 | + $specific_activity_triggers['gamipress_bookingpress_user_pending_appointment_service'] = array( 'bookingpress_service' ); | |
| 57 | + | |
| 58 | + return $specific_activity_triggers; | |
| 59 | +} | |
| 60 | +add_filter( 'gamipress_specific_activity_triggers', 'gamipress_bookingpress_specific_activity_triggers' ); | |
| 61 | + | |
| 62 | +/** | |
| 63 | + * Register specific activity triggers labels | |
| 64 | + * | |
| 65 | + * @since 1.0.0 | |
| 66 | + * | |
| 67 | + * @param array $specific_activity_trigger_labels | |
| 68 | + * @return array | |
| 69 | + */ | |
| 70 | +function gamipress_bookingpress_specific_activity_trigger_label( $specific_activity_trigger_labels ) { | |
| 71 | + | |
| 72 | + $specific_activity_trigger_labels['gamipress_bookingpress_user_books_appointment_service'] = __( 'Book an appointment for %s service', 'gamipress' ); | |
| 73 | + $specific_activity_trigger_labels['gamipress_bookingpress_user_approves_appointment_service'] = __( 'Approves an appointment for %s service', 'gamipress' ); | |
| 74 | + $specific_activity_trigger_labels['gamipress_bookingpress_user_rejects_appointment_service'] = __( 'Reject an appointment for %s service', 'gamipress' ); | |
| 75 | + $specific_activity_trigger_labels['gamipress_bookingpress_user_cancels_appointment_service'] = __( 'Cancel an appointment for %s service', 'gamipress' ); | |
| 76 | + $specific_activity_trigger_labels['gamipress_bookingpress_user_pending_appointment_service'] = __( 'Set to pending an appointment for %s service', 'gamipress' ); | |
| 77 | + | |
| 78 | + return $specific_activity_trigger_labels; | |
| 79 | +} | |
| 80 | +add_filter( 'gamipress_specific_activity_trigger_label', 'gamipress_bookingpress_specific_activity_trigger_label' ); | |
| 81 | + | |
| 82 | +/** | |
| 83 | + * Get plugin specific activity trigger post title | |
| 84 | + * | |
| 85 | + * @since 1.0.0 | |
| 86 | + * | |
| 87 | + * @param string $post_title | |
| 88 | + * @param integer $specific_id | |
| 89 | + * @param string $trigger_type | |
| 90 | + * | |
| 91 | + * @return string | |
| 92 | + */ | |
| 93 | +function gamipress_bookingpress_specific_activity_trigger_post_title( $post_title, $specific_id, $trigger_type ) { | |
| 94 | + | |
| 95 | + switch( $trigger_type ) { | |
| 96 | + case 'gamipress_bookingpress_user_books_appointment_service': | |
| 97 | + if( absint( $specific_id ) !== 0 ) { | |
| 98 | + // Get the service title | |
| 99 | + $service_title = gamipress_bookingpress_get_service_title( $specific_id ); | |
| 100 | + | |
| 101 | + $post_title = $service_title; | |
| 102 | + } | |
| 103 | + break; | |
| 104 | + case 'gamipress_bookingpress_user_approves_appointment_service': | |
| 105 | + if( absint( $specific_id ) !== 0 ) { | |
| 106 | + // Get the service title | |
| 107 | + $service_title = gamipress_bookingpress_get_service_title( $specific_id ); | |
| 108 | + | |
| 109 | + $post_title = $service_title; | |
| 110 | + } | |
| 111 | + break; | |
| 112 | + case 'gamipress_bookingpress_user_rejects_appointment_service': | |
| 113 | + if( absint( $specific_id ) !== 0 ) { | |
| 114 | + // Get the service title | |
| 115 | + $service_title = gamipress_bookingpress_get_service_title( $specific_id ); | |
| 116 | + | |
| 117 | + $post_title = $service_title; | |
| 118 | + } | |
| 119 | + break; | |
| 120 | + case 'gamipress_bookingpress_user_cancels_appointment_service': | |
| 121 | + if( absint( $specific_id ) !== 0 ) { | |
| 122 | + // Get the service title | |
| 123 | + $service_title = gamipress_bookingpress_get_service_title( $specific_id ); | |
| 124 | + | |
| 125 | + $post_title = $service_title; | |
| 126 | + } | |
| 127 | + break; | |
| 128 | + case 'gamipress_bookingpress_user_pending_appointment_service': | |
| 129 | + if( absint( $specific_id ) !== 0 ) { | |
| 130 | + // Get the service title | |
| 131 | + $service_title = gamipress_bookingpress_get_service_title( $specific_id ); | |
| 132 | + | |
| 133 | + $post_title = $service_title; | |
| 134 | + } | |
| 135 | + break; | |
| 136 | + } | |
| 137 | + | |
| 138 | + return $post_title; | |
| 139 | + | |
| 140 | +} | |
| 141 | +add_filter( 'gamipress_specific_activity_trigger_post_title', 'gamipress_bookingpress_specific_activity_trigger_post_title', 10, 3 ); | |
| 142 | + | |
| 143 | +/** | |
| 144 | + * Get plugin specific activity trigger permalink | |
| 145 | + * | |
| 146 | + * @since 1.0.0 | |
| 147 | + * | |
| 148 | + * @param string $permalink | |
| 149 | + * @param integer $specific_id | |
| 150 | + * @param string $trigger_type | |
| 151 | + * @param integer $site_id | |
| 152 | + * | |
| 153 | + * @return string | |
| 154 | + */ | |
| 155 | +function gamipress_bookingpress_specific_activity_trigger_permalink( $permalink, $specific_id, $trigger_type, $site_id ) { | |
| 156 | + | |
| 157 | + switch( $trigger_type ) { | |
| 158 | + case 'gamipress_bookingpress_user_books_appointment_service': | |
| 159 | + case 'gamipress_bookingpress_user_approves_appointment_service': | |
| 160 | + case 'gamipress_bookingpress_user_rejects_appointment_service': | |
| 161 | + case 'gamipress_bookingpress_user_cancels_appointment_service': | |
| 162 | + case 'gamipress_bookingpress_user_pending_appointment_service': | |
| 163 | + $permalink = ''; | |
| 164 | + break; | |
| 165 | + } | |
| 166 | + | |
| 167 | + return $permalink; | |
| 168 | + | |
| 169 | +} | |
| 170 | +add_filter( 'gamipress_specific_activity_trigger_permalink', 'gamipress_bookingpress_specific_activity_trigger_permalink', 10, 4 ); | |
| 171 | + | |
| 172 | +/** | |
| 173 | + * Get user for a given trigger action. | |
| 174 | + * | |
| 175 | + * @since 1.0.0 | |
| 176 | + * | |
| 177 | + * @param integer $user_id user ID to override. | |
| 178 | + * @param string $trigger Trigger name. | |
| 179 | + * @param array $args Passed trigger args. | |
| 180 | + * @return integer User ID. | |
| 181 | + */ | |
| 182 | +function gamipress_bookingpress_trigger_get_user_id( $user_id, $trigger, $args ) { | |
| 183 | + | |
| 184 | + switch ( $trigger ) { | |
| 185 | + // Appointments | |
| 186 | + case 'gamipress_bookingpress_user_register_customer': | |
| 187 | + case 'gamipress_bookingpress_user_books_appointment': | |
| 188 | + case 'gamipress_bookingpress_user_books_appointment_service': | |
| 189 | + case 'gamipress_bookingpress_user_approves_appointment': | |
| 190 | + case 'gamipress_bookingpress_user_approves_appointment_service': | |
| 191 | + case 'gamipress_bookingpress_user_rejects_appointment': | |
| 192 | + case 'gamipress_bookingpress_user_rejects_appointment_service': | |
| 193 | + case 'gamipress_bookingpress_user_cancels_appointment': | |
| 194 | + case 'gamipress_bookingpress_user_cancels_appointment_service': | |
| 195 | + case 'gamipress_bookingpress_user_pending_appointment': | |
| 196 | + case 'gamipress_bookingpress_user_pending_appointment_service': | |
| 197 | + $user_id = $args[1]; | |
| 198 | + break; | |
| 199 | + } | |
| 200 | + | |
| 201 | + return $user_id; | |
| 202 | + | |
| 203 | +} | |
| 204 | +add_filter( 'gamipress_trigger_get_user_id', 'gamipress_bookingpress_trigger_get_user_id', 10, 3 ); | |
| 205 | + | |
| 206 | +/** | |
| 207 | + * Get the id for a given specific trigger action. | |
| 208 | + * | |
| 209 | + * @since 1.0.0 | |
| 210 | + * | |
| 211 | + * @param integer $specific_id Specific ID to override. | |
| 212 | + * @param string $trigger Trigger name. | |
| 213 | + * @param array $args Passed trigger args. | |
| 214 | + * | |
| 215 | + * @return integer Specific ID. | |
| 216 | + */ | |
| 217 | +function gamipress_bookingpress_specific_trigger_get_id( $specific_id, $trigger, $args ) { | |
| 218 | + | |
| 219 | + switch ( $trigger ) { | |
| 220 | + case 'gamipress_bookingpress_user_books_appointment_service': | |
| 221 | + case 'gamipress_bookingpress_user_approves_appointment_service': | |
| 222 | + case 'gamipress_bookingpress_user_rejects_appointment_service': | |
| 223 | + case 'gamipress_bookingpress_user_cancels_appointment_service': | |
| 224 | + case 'gamipress_bookingpress_user_pending_appointment_service': | |
| 225 | + $specific_id = $args[0]; | |
| 226 | + break; | |
| 227 | + } | |
| 228 | + | |
| 229 | + return $specific_id; | |
| 230 | + | |
| 231 | +} | |
| 232 | + | |
| 233 | +add_filter( 'gamipress_specific_trigger_get_id', 'gamipress_bookingpress_specific_trigger_get_id', 10, 3 ); | |
| 234 | + | |
| 235 | +/** | |
| 236 | + * Extended meta data for event trigger logging | |
| 237 | + * | |
| 238 | + * @since 1.0.2 | |
| 239 | + * | |
| 240 | + * @param array $log_meta | |
| 241 | + * @param integer $user_id | |
| 242 | + * @param string $trigger | |
| 243 | + * @param integer $site_id | |
| 244 | + * @param array $args | |
| 245 | + * | |
| 246 | + * @return array | |
| 247 | + */ | |
| 248 | +function gamipress_bookingpress_log_event_trigger_meta_data( $log_meta, $user_id, $trigger, $site_id, $args ) { | |
| 249 | + | |
| 250 | + switch ( $trigger ) { | |
| 251 | + | |
| 252 | + // Appointments | |
| 253 | + case 'gamipress_bookingpress_user_books_appointment': | |
| 254 | + case 'gamipress_bookingpress_user_books_appointment_service': | |
| 255 | + case 'gamipress_bookingpress_user_approves_appointment': | |
| 256 | + case 'gamipress_bookingpress_user_approves_appointment_service': | |
| 257 | + case 'gamipress_bookingpress_user_rejects_appointment': | |
| 258 | + case 'gamipress_bookingpress_user_rejects_appointment_service': | |
| 259 | + case 'gamipress_bookingpress_user_cancels_appointment': | |
| 260 | + case 'gamipress_bookingpress_user_cancels_appointment_service': | |
| 261 | + case 'gamipress_bookingpress_user_pending_appointment': | |
| 262 | + case 'gamipress_bookingpress_user_pending_appointment_service': | |
| 263 | + // Add the service ID | |
| 264 | + $log_meta['service_id'] = $args[0]; | |
| 265 | + break; | |
| 266 | + } | |
| 267 | + | |
| 268 | + return $log_meta; | |
| 269 | +} | |
| 270 | +add_filter( 'gamipress_log_event_trigger_meta_data', 'gamipress_bookingpress_log_event_trigger_meta_data', 10, 5 ); | |