| @@ -23,8 +23,15 @@ | ||
| 23 | 23 | |
| 24 | 24 | if ($status != 'yes' || ($frequency == 'weekly' && $sendingDay != $currentDay)) { |
| 25 | 25 | return; |
| 26 | 26 | } |
| 27 | + | |
| 28 | + $lastSend = get_option('fcom_last_summary_email_send'); | |
| 29 | + $interval = ($frequency == 'daily') ? DAY_IN_SECONDS : WEEK_IN_SECONDS; | |
| 30 | + if ($lastSend && (current_time('timestamp') - strtotime($lastSend)) < $interval) { | |
| 31 | + return; | |
| 32 | + } | |
| 33 | + | |
| 27 | 34 | $reportDays = $frequency == 'daily' ? 1 : 7; |
| 28 | 35 | |
| 29 | 36 | $reportDateFrom = gmdate('Y-m-d H:i:s', strtotime("-$reportDays days")); |
| 30 | 37 | |
| @@ -47,16 +54,25 @@ | ||
| 47 | 54 | 'totalBooked' => $totalBooked, |
| 48 | 55 | 'totalCompleted' => $totalCompleted, |
| 49 | 56 | ]; |
| 50 | 57 | |
| 51 | - $adminEmail = str_replace('{{wp.admin_email}}', get_option('admin_email'), $adminEmail); | |
| 52 | - | |
| 58 | + $adminEmail = str_replace('{{wp.admin_email}}', (string) get_option('admin_email', ''), $adminEmail); | |
| 53 | 59 | if(!$adminEmail) { |
| 54 | 60 | return; |
| 55 | 61 | } |
| 56 | 62 | |
| 57 | - // translators: %d is replaced with the number of days | |
| 58 | - $emailSubject = sprintf(esc_html__('Email Summary of Your Bookings (Last %d Days)', 'fluent-booking'), $reportDays); | |
| 63 | + update_option('fcom_last_summary_email_send', current_time('mysql')); | |
| 64 | + | |
| 65 | + $emailSubject = sprintf( | |
| 66 | + // translators: %d: number of days for which the summary is being reported | |
| 67 | + esc_html(_n( | |
| 68 | + 'Email Summary of Your Bookings (Last %d Day)', | |
| 69 | + 'Email Summary of Your Bookings (Last %d Days)', | |
| 70 | + $reportDays, | |
| 71 | + 'fluent-booking' | |
| 72 | + )), | |
| 73 | + $reportDays | |
| 74 | + ); | |
| 59 | 75 | |
| 60 | 76 | $emailBody = (string)App::make('view')->make('emails.summary_report', $data); |
| 61 | 77 | |
| 62 | 78 | $emogrifier = new Emogrifier($emailBody); |