PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
← All changes | app/Services/EmailNotificationService.php +61 -36 1.5.25 → 2.5.0 View file →
@@ -13,8 +13,9 @@
13 13 * @param \FluentBooking\App\Models\Booking $booking
14 14 * @param $email
15 15 * @param $emailTo
16 16 * @param $actionType
17 + * @param bool $resending
17 18 * @return bool|mixed
18 19 */
19 20 public static function emailOnBooked(Booking $booking, $email, $emailTo, $actionType = 'scheduled', $resending = false)
20 21 {
@@ -89,21 +90,26 @@
89 90 $body = (string)$emogrifier->emogrify();
90 91
91 92 $result = Mailer::send($to, $emailSubject, $body, $headers, $attachments);
92 93
93 - if ($attachments) {
94 - wp_delete_file($attachments[0]);
94 + foreach ($attachments as $attachment) {
95 + wp_delete_file($attachment);
95 96 }
96 97
97 - $status = $result ? 'sent' : 'sending failed';
98 + $actionTypeLabel = $actionType == 'request' ? __('request', 'fluent-booking') : __('scheduled', 'fluent-booking');
99 + $recipientLabel = $emailTo == 'guest' ? __('guest', 'fluent-booking') : __('host', 'fluent-booking');
100 + $statusLabel = $result ? __('sent', 'fluent-booking') : __('sending failed', 'fluent-booking');
101 + $logType = $result ? 'activity' : 'error';
98 102
99 - $title = sprintf(__('Booking %s email %s to %s', 'fluent-booking'), $actionType, $status, $emailTo);
103 + $title = sprintf(
104 + /* translators: %1$s: Action type, %2$s: Status, %3$s: Recipient */
105 + __('Booking %1$s email %2$s to %3$s', 'fluent-booking'),
106 + $actionTypeLabel,
107 + $statusLabel,
108 + $recipientLabel
109 + );
100 110
101 - if ($result) {
102 - self::addLog($title, $title, $booking->id);
103 - } else {
104 - self::addLog($title, $title, $booking->id, 'error');
105 - }
111 + self::addLog($title, $title, $booking->id, $logType);
106 112
107 113 return $result;
108 114 }
109 115
@@ -180,17 +186,25 @@
180 186 $body = (string)$emogrifier->emogrify();
181 187
182 188 $result = Mailer::send($to, $subject, $body, $headers);
183 189
184 - if (!$result) {
185 - return false;
186 - }
190 + $recipientLabel = $emailTo == 'guest' ? __('guest', 'fluent-booking') : __('host', 'fluent-booking');
191 + $statusLabel = $result ? __('sent', 'fluent-booking') : __('sending failed', 'fluent-booking');
192 + $logType = $result ? 'activity' : 'error';
187 193
188 - $title = __('Reminder Email Sent', 'fluent-booking');
189 - $description = sprintf(__('Reminder email sent to %s.', 'fluent-booking'), $emailTo);
190 - self::addLog($title, $description, $booking->id);
194 + $title = sprintf(
195 + /* translators: %1$s: Status, %2$s: Recipient */
196 + __('Booking reminder email %1$s to %2$s', 'fluent-booking'),
197 + $statusLabel,
198 + $recipientLabel
199 + );
191 200
192 - return true;
201 + /* translators: %1$s: Status, %2$s: Recipient */
202 + $description = sprintf(__('Reminder email %1$s to %2$s.', 'fluent-booking'), $statusLabel, $recipientLabel);
203 +
204 + self::addLog($title, $description, $booking->id, $logType);
205 +
206 + return $result;
193 207 }
194 208
195 209 /**
196 210 * @param \FluentBooking\App\Models\Booking $booking
@@ -266,20 +280,23 @@
266 280 $body = (string)$emogrifier->emogrify();
267 281
268 282 $result = Mailer::send($to, $subject, $body, $headers);
269 283
270 - $actionType = $actionType == 'reject' ? __('Rejection', 'fluent-booking') : __('Cancellation', 'fluent-booking');
284 + $actionTypeLabel = $actionType == 'reject' ? __('Rejection', 'fluent-booking') : __('Cancellation', 'fluent-booking');
285 + $recipientLabel = $emailTo == 'guest' ? __('guest', 'fluent-booking') : __('host', 'fluent-booking');
286 + $statusLabel = $result ? __('sent', 'fluent-booking') : __('sending failed', 'fluent-booking');
287 + $logType = $result ? 'activity' : 'error';
271 288
272 - $status = $result ? 'sent' : 'sending failed';
289 + $title = sprintf(
290 + /* translators: %1$s: Action type, %2$s: Status, %3$s: Recipient */
291 + __('Booking %1$s email %2$s to %3$s', 'fluent-booking'),
292 + $actionTypeLabel,
293 + $statusLabel,
294 + $recipientLabel
295 + );
273 296
274 - $title = sprintf(__('%s email %s to %s', 'fluent-booking'), $actionType, $status, $emailTo);
297 + self::addLog($title, $title, $booking->id, $logType);
275 298
276 - if ($result) {
277 - self::addLog($title, $title, $booking->id);
278 - } else {
279 - self::addLog($title, $title, $booking->id, 'error');
280 - }
281 -
282 299 return $result;
283 300 }
284 301
285 302 /**
@@ -365,19 +382,23 @@
365 382 if ($attachments) {
366 383 wp_delete_file($attachments[0]);
367 384 }
368 385
369 - $status = $result ? 'sent' : 'sending failed';
386 + $statusLabel = $result ? __('sent', 'fluent-booking') : __('sending failed', 'fluent-booking');
387 + $recipientLabel = $emailTo == 'guest' ? __('guest', 'fluent-booking') : __('host', 'fluent-booking');
388 + $logType = $result ? 'activity' : 'error';
370 389
371 - $title = sprintf(__('Rescheduled booking email %s to $s', 'fluent-booking'), $status, $emailTo);
390 + $title = sprintf(
391 + /* translators: %1$s: Status, %2$s: Recipient */
392 + __('Rescheduled booking email %1$s to %2$s', 'fluent-booking'),
393 + $statusLabel,
394 + $recipientLabel
395 + );
372 396
373 - $description = sprintf(__('Rescheduling email %s to %s', 'fluent-booking'), $status, $emailTo);
397 + /* translators: %1$s: Status, %2$s: Recipient */
398 + $description = sprintf(__('Rescheduling email %1$s to %2$s', 'fluent-booking'), $statusLabel, $recipientLabel);
374 399
375 - if ($result) {
376 - self::addLog($title, $description, $booking->id);
377 - } else {
378 - self::addLog($title, $description, $booking->id, 'error');
379 - }
400 + self::addLog($title, $description, $booking->id, $logType);
380 401
381 402 return $result;
382 403 }
383 404
@@ -414,18 +435,22 @@
414 435 }
415 436
416 437 private static function prepareAttachments($booking)
417 438 {
439 + require_once ABSPATH . 'wp-admin/includes/file.php';
440 +
418 441 if (!WP_Filesystem()) {
419 442 return [];
420 443 }
421 444
422 445 $icsContent = BookingService::generateBookingICS($booking);
423 -
424 - $filePath = wp_tempnam(null, 'event') . '.ics';
425 -
446 +
447 + $icsFileName = 'fcal-' . md5(wp_generate_uuid4()) . '.ics';
448 + $filePath = trailingslashit(wp_upload_dir()['path']) . $icsFileName;
449 +
426 450 global $wp_filesystem;
427 451 $wp_filesystem->put_contents($filePath, $icsContent);
452 +
428 453 return [$filePath];
429 454 }
430 455
431 456 protected static function addLog($title, $description, $bookingId, $type = 'activity')