PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 4.3.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v4.3.0
0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / src / Tasks / Reports / SummaryEmailTask.php
wp-mail-smtp / src / Tasks / Reports Last commit date
SummaryEmailTask.php 1 year ago
SummaryEmailTask.php
105 lines
1 <?php
2
3 namespace WPMailSMTP\Tasks\Reports;
4
5 use WPMailSMTP\Tasks\Tasks;
6 use WPMailSMTP\WP;
7 use WPMailSMTP\Tasks\Task;
8 use WPMailSMTP\Reports\Emails\Summary as SummaryReportEmail;
9
10 /**
11 * Class SummaryEmailTask.
12 *
13 * @since 3.0.0
14 */
15 class SummaryEmailTask extends Task {
16
17 /**
18 * Action name for this task.
19 *
20 * @since 3.0.0
21 */
22 const ACTION = 'wp_mail_smtp_summary_report_email';
23
24 /**
25 * Class constructor.
26 *
27 * @since 3.0.0
28 */
29 public function __construct() {
30
31 parent::__construct( self::ACTION );
32 }
33
34 /**
35 * Initialize the task with all the proper checks.
36 *
37 * @since 3.0.0
38 */
39 public function init() {
40
41 // Register the action handler.
42 add_action( self::ACTION, array( $this, 'process' ) );
43
44 $is_disabled = SummaryReportEmail::is_disabled();
45
46 // Exit if summary report email is disabled or this task is already scheduled.
47 if ( ! empty( $is_disabled ) || Tasks::is_scheduled( self::ACTION ) !== false ) {
48 return;
49 }
50
51 $date = new \DateTime( 'next monday 2pm', WP::wp_timezone() );
52
53 // Schedule the task.
54 $this
55 ->recurring( $date->getTimestamp(), WEEK_IN_SECONDS )
56 ->unique()
57 ->register();
58 }
59
60 /**
61 * Process summary report email send.
62 *
63 * @since 3.0.0
64 *
65 * @param int $meta_id The Meta ID with the stored task parameters.
66 */
67 public function process( $meta_id ) {
68
69 // Prevent email sending if summary report email is disabled.
70 if ( SummaryReportEmail::is_disabled() || ! $this->is_allowed() ) {
71 return;
72 }
73
74 // Update the last sent week at the top to prevent multiple emails in case of task failure and retry.
75 update_option( 'wp_mail_smtp_summary_report_email_last_sent_week', current_time( 'W' ) );
76
77 $reports = wp_mail_smtp()->get_reports();
78
79 $email = $reports->get_summary_report_email();
80
81 $email->send();
82 }
83
84 /**
85 * Check if the summary report email is allowed to be sent.
86 *
87 * The email is allowed to be sent if it was not sent in the current week.
88 *
89 * @since 4.1.1
90 *
91 * @return bool
92 */
93 private function is_allowed() {
94
95 $last_sent_week = get_option( 'wp_mail_smtp_summary_report_email_last_sent_week' );
96 $current_week = current_time( 'W' );
97
98 if ( $last_sent_week === false || ( (int) $current_week !== (int) $last_sent_week ) ) {
99 return true;
100 }
101
102 return false;
103 }
104 }
105