| @@ -1,10 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Booktics\Admin; |
| 4 | 4 | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) exit; | |
| 6 | + | |
| 5 | 7 | use Booktics\Contracts\Hookable_Service_Contract; |
| 6 | -use ENS\Core\SDK; | |
| 8 | +use Ens\Core\SDK; | |
| 7 | 9 | |
| 8 | 10 | class Notification implements Hookable_Service_Contract { |
| 9 | 11 | |
| 10 | 12 | /** |
| @@ -13,8 +15,10 @@ | ||
| 13 | 15 | * @return void |
| 14 | 16 | */ |
| 15 | 17 | public function register() { |
| 16 | 18 | if ( class_exists( SDK::class ) ) { |
| 19 | + add_filter( 'notification_sdk_email_body', [ $this, 'wrap_email_body' ], 10, 1 ); | |
| 20 | + | |
| 17 | 21 | SDK::get_instance() |
| 18 | 22 | ->setup( |
| 19 | 23 | array( |
| 20 | 24 | 'plugin_name' => 'Booktics', |
| @@ -19,8 +23,9 @@ | ||
| 19 | 23 | array( |
| 20 | 24 | 'plugin_name' => 'Booktics', |
| 21 | 25 | 'plugin_slug' => 'booktics', |
| 22 | 26 | 'general_prefix' => 'bt', |
| 27 | + 'hook_prefix' => 'booktics', | |
| 23 | 28 | 'text_domain' => 'booktics', |
| 24 | 29 | 'admin_script_handler' => 'booktics-dashboard-scripts', |
| 25 | 30 | 'sub_menu_filter_hook' => 'booktics_menu', |
| 26 | 31 | 'sub_menu_details' => |
| @@ -34,32 +39,100 @@ | ||
| 34 | 39 | ) |
| 35 | 40 | ) |
| 36 | 41 | ->init(); |
| 37 | 42 | |
| 38 | - add_filter( | |
| 39 | - 'ens_available_actions', function ( $actions ) { | |
| 43 | + add_filter( | |
| 44 | + 'ens_bt_available_actions', function ( $actions ) { | |
| 45 | + // Google Meet link generation is gated behind Pro (the pro plugin is what | |
| 46 | + // adds the enable_google_meet field to the service model), but the tag | |
| 47 | + // itself is registered here in free. Without this, a free user picks the | |
| 48 | + // tag, gets an empty value in the email and reads it as a broken feature. | |
| 49 | + $meet_label = booktics_is_pro_active() | |
| 50 | + ? __( 'Google Meet URL', 'booktics' ) | |
| 51 | + : __( 'Google Meet URL (Pro)', 'booktics' ); | |
| 52 | + | |
| 40 | 53 | $actions = array( |
| 41 | 54 | array( |
| 42 | - 'trigger_label' => 'Order Created', | |
| 55 | + 'trigger_label' => __( 'Order Created', 'booktics' ), | |
| 43 | 56 | 'trigger_value' => 'order_created', |
| 44 | 57 | 'trigger_data' => array( |
| 45 | 58 | array( |
| 46 | - 'label' => 'Order No', | |
| 59 | + 'label' => __( 'Order No', 'booktics' ), | |
| 47 | 60 | 'value' => 'order_no', |
| 48 | 61 | 'type' => 'string', |
| 49 | 62 | ), |
| 50 | 63 | array( |
| 51 | - 'label' => 'Order Date', | |
| 64 | + 'label' => __( 'Order Status', 'booktics' ), | |
| 65 | + 'value' => 'order_status', | |
| 66 | + 'type' => 'string', | |
| 67 | + ), | |
| 68 | + array( | |
| 69 | + 'label' => __( 'Order Date', 'booktics' ), | |
| 52 | 70 | 'value' => 'order_date', |
| 53 | 71 | 'type' => 'date', |
| 54 | 72 | ), |
| 55 | 73 | array( |
| 56 | - 'label' => 'Order Total', | |
| 74 | + 'label' => __( 'Service Name', 'booktics' ), | |
| 75 | + 'value' => 'service_name', | |
| 76 | + 'type' => 'string', | |
| 77 | + ), | |
| 78 | + array( | |
| 79 | + 'label' => __( 'Team Name', 'booktics' ), | |
| 80 | + 'value' => 'team_name', | |
| 81 | + 'type' => 'string', | |
| 82 | + ), | |
| 83 | + array( | |
| 84 | + 'label' => __( 'Appointment Date', 'booktics' ), | |
| 85 | + 'value' => 'appointment_date', | |
| 86 | + 'type' => 'date', | |
| 87 | + ), | |
| 88 | + array( | |
| 89 | + 'label' => __( 'Appointment Status', 'booktics' ), | |
| 90 | + 'value' => 'appointment_status', | |
| 91 | + 'type' => 'string', | |
| 92 | + ), | |
| 93 | + array( | |
| 94 | + 'label' => __( 'Start Time', 'booktics' ), | |
| 95 | + 'value' => 'start_time', | |
| 96 | + 'type' => 'string', | |
| 97 | + ), | |
| 98 | + array( | |
| 99 | + 'label' => __( 'End Time', 'booktics' ), | |
| 100 | + 'value' => 'end_time', | |
| 101 | + 'type' => 'string', | |
| 102 | + ), | |
| 103 | + array( | |
| 104 | + 'label' => __( 'Location Address', 'booktics' ), | |
| 105 | + 'value' => 'location_address', | |
| 106 | + 'type' => 'string', | |
| 107 | + ), | |
| 108 | + array( | |
| 109 | + 'label' => __( 'Order Total', 'booktics' ), | |
| 57 | 110 | 'value' => 'order_total', |
| 58 | 111 | 'type' => 'string', |
| 59 | 112 | ), |
| 60 | 113 | array( |
| 61 | - 'label' => 'User Email', | |
| 114 | + 'label' => __( 'Customer Name', 'booktics' ), | |
| 115 | + 'value' => 'customer_name', | |
| 116 | + 'type' => 'string', | |
| 117 | + ), | |
| 118 | + array( | |
| 119 | + 'label' => $meet_label, | |
| 120 | + 'value' => 'google_meet_url', | |
| 121 | + 'type' => 'string', | |
| 122 | + ), | |
| 123 | + array( | |
| 124 | + 'label' => __( 'Appointment Reschedule Url', 'booktics' ), | |
| 125 | + 'value' => 'appointment_reschedule_url', | |
| 126 | + 'type' => 'string', | |
| 127 | + ), | |
| 128 | + array( | |
| 129 | + 'label' => __( 'Appointment Cancel Url', 'booktics' ), | |
| 130 | + 'value' => 'appointment_cancel_url', | |
| 131 | + 'type' => 'string', | |
| 132 | + ), | |
| 133 | + array( | |
| 134 | + 'label' => __( 'User Email', 'booktics' ), | |
| 62 | 135 | 'value' => 'user_email', |
| 63 | 136 | 'type' => 'string', |
| 64 | 137 | ), |
| 65 | 138 | ), |
| @@ -70,44 +143,121 @@ | ||
| 70 | 143 | ), |
| 71 | 144 | ), |
| 72 | 145 | 'email_receivers' => array( |
| 73 | 146 | array( |
| 74 | - 'label' => 'User Email', | |
| 147 | + 'label' => __( 'User Email', 'booktics' ), | |
| 75 | 148 | 'value' => 'user_email', |
| 76 | 149 | ), |
| 77 | 150 | ), |
| 78 | 151 | ), |
| 79 | 152 | array( |
| 80 | - 'trigger_label' => 'Appointment Rescheduled', | |
| 153 | + 'trigger_label' => __( 'Appointment Scheduled', 'booktics' ), | |
| 154 | + 'trigger_value' => 'appointment_scheduled', | |
| 155 | + 'trigger_data' => array( | |
| 156 | + array( | |
| 157 | + 'label' => __( 'Service Name', 'booktics' ), | |
| 158 | + 'value' => 'appointment_service', | |
| 159 | + 'type' => 'string', | |
| 160 | + ), | |
| 161 | + array( | |
| 162 | + 'label' => __( 'Team Member Name', 'booktics' ), | |
| 163 | + 'value' => 'appointment_team_member', | |
| 164 | + 'type' => 'string', | |
| 165 | + ), | |
| 166 | + array( | |
| 167 | + 'label' => __( 'Appointment Date', 'booktics' ), | |
| 168 | + 'value' => 'appointment_date', | |
| 169 | + 'type' => 'date', | |
| 170 | + ), | |
| 171 | + array( | |
| 172 | + 'label' => __( 'Appointment Start Time', 'booktics' ), | |
| 173 | + 'value' => 'start_time', | |
| 174 | + 'type' => 'string', | |
| 175 | + ), | |
| 176 | + array( | |
| 177 | + 'label' => __( 'Appointment Time', 'booktics' ), | |
| 178 | + 'value' => 'appointment_time', | |
| 179 | + 'type' => 'date', | |
| 180 | + ), | |
| 181 | + array( | |
| 182 | + 'label' => __( 'Attendee Count', 'booktics' ), | |
| 183 | + 'value' => 'attendee_count', | |
| 184 | + 'type' => 'string', | |
| 185 | + ), | |
| 186 | + array( | |
| 187 | + 'label' => __( 'Customer Name', 'booktics' ), | |
| 188 | + 'value' => 'customer_name', | |
| 189 | + 'type' => 'string', | |
| 190 | + ), | |
| 191 | + array( | |
| 192 | + 'label' => __( 'User Email', 'booktics' ), | |
| 193 | + 'value' => 'user_email', | |
| 194 | + 'type' => 'string', | |
| 195 | + ), | |
| 196 | + array( | |
| 197 | + 'label' => $meet_label, | |
| 198 | + 'value' => 'google_meet_url', | |
| 199 | + 'type' => 'string', | |
| 200 | + ), | |
| 201 | + array( | |
| 202 | + 'label' => __( 'Extra Services', 'booktics' ), | |
| 203 | + 'value' => 'extra_services', | |
| 204 | + 'type' => 'string', | |
| 205 | + ), | |
| 206 | + ), | |
| 207 | + 'delay_dependencies' => array( | |
| 208 | + array( | |
| 209 | + 'label' => __( 'Appointment Time', 'booktics' ), | |
| 210 | + 'value' => 'before_appointment_time', | |
| 211 | + ), | |
| 212 | + ), | |
| 213 | + 'email_receivers' => array( | |
| 214 | + array( | |
| 215 | + 'label' => __( 'User Email', 'booktics' ), | |
| 216 | + 'value' => 'user_email', | |
| 217 | + ), | |
| 218 | + array( | |
| 219 | + 'label' => __( 'Team Member Email', 'booktics' ), | |
| 220 | + 'value' => 'appointment_team_member_email', | |
| 221 | + ), | |
| 222 | + ), | |
| 223 | + ), | |
| 224 | + array( | |
| 225 | + 'trigger_label' => __( 'Appointment Rescheduled', 'booktics' ), | |
| 81 | 226 | 'trigger_value' => 'appointment_rescheduled', |
| 82 | 227 | 'trigger_data' => array( |
| 83 | 228 | array( |
| 84 | - 'label' => 'Service Name', | |
| 229 | + 'label' => __( 'Service Name', 'booktics' ), | |
| 85 | 230 | 'value' => 'appointment_service', |
| 86 | 231 | 'type' => 'string', |
| 87 | 232 | ), |
| 88 | 233 | array( |
| 89 | - 'label' => 'Date', | |
| 234 | + 'label' => __( 'Date', 'booktics' ), | |
| 90 | 235 | 'value' => 'date', |
| 91 | 236 | 'type' => 'date', |
| 92 | 237 | ), |
| 93 | 238 | array( |
| 94 | - 'label' => 'Team Member Name', | |
| 239 | + 'label' => __( 'Team Member Name', 'booktics' ), | |
| 95 | 240 | 'value' => 'appointment_team_member', |
| 96 | 241 | 'type' => 'string', |
| 97 | 242 | ), |
| 98 | 243 | array( |
| 99 | - 'label' => 'Start Time', | |
| 244 | + 'label' => __( 'Start Time', 'booktics' ), | |
| 100 | 245 | 'value' => 'start_time', |
| 101 | 246 | 'type' => 'string', |
| 102 | 247 | ), |
| 103 | 248 | array( |
| 104 | - 'label' => 'End Time', | |
| 249 | + 'label' => __( 'End Time', 'booktics' ), | |
| 105 | 250 | 'value' => 'end_time', |
| 106 | 251 | 'type' => 'string', |
| 107 | 252 | ), |
| 253 | + array( | |
| 254 | + 'label' => __( 'Customer Name', 'booktics' ), | |
| 255 | + 'value' => 'customer_name', | |
| 256 | + 'type' => 'string', | |
| 257 | + ), | |
| 108 | 258 | array( |
| 109 | - 'label' => 'User Email', | |
| 259 | + 'label' => __( 'User Email', 'booktics' ), | |
| 110 | 260 | 'value' => 'user_email', |
| 111 | 261 | 'type' => 'string', |
| 112 | 262 | ), |
| 113 | 263 | ), |
| @@ -112,50 +262,59 @@ | ||
| 112 | 262 | ), |
| 113 | 263 | ), |
| 114 | 264 | 'delay_dependencies' => array( |
| 115 | 265 | array( |
| 116 | - 'label' => 'Date', | |
| 266 | + 'label' => __( 'Date', 'booktics' ), | |
| 117 | 267 | 'value' => 'date', |
| 118 | 268 | ), |
| 119 | 269 | ), |
| 120 | 270 | 'email_receivers' => array( |
| 121 | 271 | array( |
| 122 | - 'label' => 'User Email', | |
| 272 | + 'label' => __( 'User Email', 'booktics' ), | |
| 123 | 273 | 'value' => 'user_email', |
| 124 | 274 | ), |
| 275 | + array( | |
| 276 | + 'label' => __( 'Team Member Email', 'booktics' ), | |
| 277 | + 'value' => 'appointment_team_member_email', | |
| 278 | + ), | |
| 125 | 279 | ), |
| 126 | 280 | ), |
| 127 | 281 | array( |
| 128 | - 'trigger_label' => 'Appointment Cancelled', | |
| 282 | + 'trigger_label' => __( 'Appointment Cancelled', 'booktics' ), | |
| 129 | 283 | 'trigger_value' => 'appointment_cancelled', |
| 130 | 284 | 'trigger_data' => array( |
| 131 | 285 | array( |
| 132 | - 'label' => 'Service Name', | |
| 286 | + 'label' => __( 'Service Name', 'booktics' ), | |
| 133 | 287 | 'value' => 'appointment_service', |
| 134 | 288 | 'type' => 'string', |
| 135 | 289 | ), |
| 136 | 290 | array( |
| 137 | - 'label' => 'Date', | |
| 291 | + 'label' => __( 'Date', 'booktics' ), | |
| 138 | 292 | 'value' => 'date', |
| 139 | 293 | 'type' => 'date', |
| 140 | 294 | ), |
| 141 | 295 | array( |
| 142 | - 'label' => 'Team Member Name', | |
| 296 | + 'label' => __( 'Team Member Name', 'booktics' ), | |
| 143 | 297 | 'value' => 'appointment_team_member', |
| 144 | 298 | 'type' => 'string', |
| 145 | 299 | ), |
| 146 | 300 | array( |
| 147 | - 'label' => 'Start Time', | |
| 301 | + 'label' => __( 'Start Time', 'booktics' ), | |
| 148 | 302 | 'value' => 'start_time', |
| 149 | 303 | 'type' => 'string', |
| 150 | 304 | ), |
| 151 | 305 | array( |
| 152 | - 'label' => 'End Time', | |
| 306 | + 'label' => __( 'End Time', 'booktics' ), | |
| 153 | 307 | 'value' => 'end_time', |
| 154 | 308 | 'type' => 'string', |
| 155 | 309 | ), |
| 310 | + array( | |
| 311 | + 'label' => __( 'Customer Name', 'booktics' ), | |
| 312 | + 'value' => 'customer_name', | |
| 313 | + 'type' => 'string', | |
| 314 | + ), | |
| 156 | 315 | array( |
| 157 | - 'label' => 'User Email', | |
| 316 | + 'label' => __( 'User Email', 'booktics' ), | |
| 158 | 317 | 'value' => 'user_email', |
| 159 | 318 | 'type' => 'string', |
| 160 | 319 | ), |
| 161 | 320 | ), |
| @@ -160,35 +319,39 @@ | ||
| 160 | 319 | ), |
| 161 | 320 | ), |
| 162 | 321 | 'delay_dependencies' => array( |
| 163 | 322 | array( |
| 164 | - 'label' => 'Date', | |
| 323 | + 'label' => __( 'Date', 'booktics' ), | |
| 165 | 324 | 'value' => 'date', |
| 166 | 325 | ), |
| 167 | 326 | ), |
| 168 | 327 | 'email_receivers' => array( |
| 169 | 328 | array( |
| 170 | - 'label' => 'User Email', | |
| 329 | + 'label' => __( 'User Email', 'booktics' ), | |
| 171 | 330 | 'value' => 'user_email', |
| 172 | 331 | ), |
| 332 | + array( | |
| 333 | + 'label' => __( 'Team Member Email', 'booktics' ), | |
| 334 | + 'value' => 'appointment_team_member_email', | |
| 335 | + ), | |
| 173 | 336 | ), |
| 174 | 337 | ), |
| 175 | 338 | array( |
| 176 | - 'trigger_label' => 'Team Member Created', | |
| 339 | + 'trigger_label' => __( 'Team Member Created', 'booktics' ), | |
| 177 | 340 | 'trigger_value' => 'team_member_created', |
| 178 | 341 | 'trigger_data' => array( |
| 179 | 342 | array( |
| 180 | - 'label' => 'Team Member Name', | |
| 343 | + 'label' => __( 'Team Member Name', 'booktics' ), | |
| 181 | 344 | 'value' => 'team_member_name', |
| 182 | 345 | 'type' => 'string', |
| 183 | 346 | ), |
| 184 | 347 | array( |
| 185 | - 'label' => 'Team Member Email', | |
| 348 | + 'label' => __( 'Team Member Email', 'booktics' ), | |
| 186 | 349 | 'value' => 'team_member_email', |
| 187 | 350 | 'type' => 'string', |
| 188 | 351 | ), |
| 189 | 352 | array( |
| 190 | - 'label' => 'Password Reset URL', | |
| 353 | + 'label' => __( 'Password Reset URL', 'booktics' ), | |
| 191 | 354 | 'value' => 'password_reset_url', |
| 192 | 355 | 'type' => 'string', |
| 193 | 356 | ), |
| 194 | 357 | ), |
| @@ -194,13 +357,61 @@ | ||
| 194 | 357 | ), |
| 195 | 358 | 'delay_dependencies' => array(), |
| 196 | 359 | 'email_receivers' => array( |
| 197 | 360 | array( |
| 198 | - 'label' => 'Team Member Email', | |
| 361 | + 'label' => __( 'Team Member Email', 'booktics' ), | |
| 199 | 362 | 'value' => 'team_member_email', |
| 200 | 363 | ), |
| 201 | 364 | ), |
| 202 | 365 | ), |
| 366 | + array( | |
| 367 | + 'trigger_label' => __( 'Customer Created', 'booktics' ), | |
| 368 | + 'trigger_value' => 'customer_created', | |
| 369 | + 'trigger_data' => array( | |
| 370 | + array( | |
| 371 | + 'label' => __( 'Customer First Name', 'booktics' ), | |
| 372 | + 'value' => 'customer_first_name', | |
| 373 | + 'type' => 'string', | |
| 374 | + ), | |
| 375 | + array( | |
| 376 | + 'label' => __( 'Customer Last Name', 'booktics' ), | |
| 377 | + 'value' => 'customer_last_name', | |
| 378 | + 'type' => 'string', | |
| 379 | + ), | |
| 380 | + array( | |
| 381 | + 'label' => __( 'Customer Full Name', 'booktics' ), | |
| 382 | + 'value' => 'customer_full_name', | |
| 383 | + 'type' => 'string', | |
| 384 | + ), | |
| 385 | + array( | |
| 386 | + 'label' => __( 'Customer Phone', 'booktics' ), | |
| 387 | + 'value' => 'customer_phone', | |
| 388 | + 'type' => 'string', | |
| 389 | + ), | |
| 390 | + array( | |
| 391 | + 'label' => __( 'Customer User Name', 'booktics' ), | |
| 392 | + 'value' => 'customer_user_name', | |
| 393 | + 'type' => 'string', | |
| 394 | + ), | |
| 395 | + array( | |
| 396 | + 'label' => __( 'Customer Email', 'booktics' ), | |
| 397 | + 'value' => 'customer_email', | |
| 398 | + 'type' => 'string', | |
| 399 | + ), | |
| 400 | + array( | |
| 401 | + 'label' => __( 'Password Reset URL', 'booktics' ), | |
| 402 | + 'value' => 'password_reset_url', | |
| 403 | + 'type' => 'string', | |
| 404 | + ), | |
| 405 | + ), | |
| 406 | + 'delay_dependencies' => array(), | |
| 407 | + 'email_receivers' => array( | |
| 408 | + array( | |
| 409 | + 'label' => __( 'Customer Email', 'booktics' ), | |
| 410 | + 'value' => 'customer_email', | |
| 411 | + ), | |
| 412 | + ), | |
| 413 | + ), | |
| 203 | 414 | ); |
| 204 | 415 | |
| 205 | 416 | return $actions; |
| 206 | 417 | } |
| @@ -205,6 +416,43 @@ | ||
| 205 | 416 | return $actions; |
| 206 | 417 | } |
| 207 | 418 | ); |
| 208 | 419 | } |
| 420 | + } | |
| 421 | + | |
| 422 | + /** | |
| 423 | + * Wrap email body with custom template | |
| 424 | + * | |
| 425 | + * @param string $message | |
| 426 | + * @return string | |
| 427 | + */ | |
| 428 | + public function wrap_email_body( $message ) { | |
| 429 | + | |
| 430 | + $template_path = BOOKTICS_DIR . '/templates/email/team-member-create.html'; | |
| 431 | + | |
| 432 | + if ( ! file_exists( $template_path ) ) { | |
| 433 | + return $message; | |
| 434 | + } | |
| 435 | + $template = file_get_contents( $template_path ); | |
| 436 | + $default_image = get_template_directory_uri() . '/assets/images/placeholder.jpg'; | |
| 437 | + $plugin_name = apply_filters( | |
| 438 | + 'booktics_plugin_name', | |
| 439 | + BOOKTICS_PLUGIN_NAME | |
| 440 | + ); | |
| 441 | + $show_powered_by = apply_filters( 'booktics_show_email_powered_by', true ); | |
| 442 | + | |
| 443 | + // Build powered-by HTML if enabled | |
| 444 | + $powered_by_html = ''; | |
| 445 | + if ( $show_powered_by ) { | |
| 446 | + $powered_by_html = '<p class="bkt-powered-by">Powered by ' . esc_html( $plugin_name ) . '</p>'; | |
| 447 | + } | |
| 448 | + $variables = array( | |
| 449 | + '{{MESSAGE}}' => wp_kses_post( $message ), | |
| 450 | + '{{COMPANY_NAME}}' => booktics_get_option( 'business_name', get_bloginfo( 'name' ) ), | |
| 451 | + '{{COMPANY_LOGO}}' => booktics_get_option( 'business_logo', $default_image ), | |
| 452 | + '{{COMPANY_ADDRESS}}' => booktics_get_option( 'business_address', 'California, USA' ), | |
| 453 | + '{%powered_by_section%}' => $powered_by_html, | |
| 454 | + ); | |
| 455 | + | |
| 456 | + return str_replace( array_keys( $variables ), array_values( $variables ), $template ); | |
| 209 | 457 | } |
| 210 | 458 | } |