PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | class/class-mainwp-notification.php +371 -241 4.6.0.1 → 6.2.2 View file →
@@ -6,287 +6,417 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +// Exit if accessed directly.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit;
13 +}
14 +
10 15 /**
11 16 * Class MainWP_Notification
12 17 *
13 18 * @package MainWP\Dashboard
14 19 */
15 -class MainWP_Notification {
20 +class MainWP_Notification { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
16 21
17 - /**
18 - * Method get_class_name()
19 - *
20 - * Get Class Name.
21 - *
22 - * @return object
23 - */
24 - public static function get_class_name() {
25 - return __CLASS__;
26 - }
22 + /**
23 + * Method get_class_name()
24 + *
25 + * Get Class Name.
26 + *
27 + * @return object
28 + */
29 + public static function get_class_name() {
30 + return __CLASS__;
31 + }
27 32
28 33
29 - /**
30 - * Method send_notify_user()
31 - *
32 - * To send user a notification.
33 - *
34 - * @param int $userId User ID.
35 - * @param string $subject Email Subject.
36 - * @param string $content Email Content.
37 - *
38 - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_notification_email()
39 - */
40 - public static function send_notify_user( $userId, $subject, $content ) {
41 - $content_type = 'content-type: text/html';
42 - self::send_wp_mail(
43 - MainWP_DB_Common::instance()->get_user_notification_email( $userId ),
44 - $subject,
45 - $content,
46 - $content_type
47 - );
48 - }
34 + /**
35 + * Method send_notify_user()
36 + *
37 + * To send user a notification.
38 + *
39 + * @param int $userId User ID.
40 + * @param string $subject Email Subject.
41 + * @param string $content Email Content.
42 + *
43 + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_notification_email()
44 + */
45 + public static function send_notify_user( $userId, $subject, $content ) {
46 + $content_type = 'content-type: text/html';
47 + static::send_wp_mail(
48 + MainWP_DB_Common::instance()->get_user_notification_email( $userId ),
49 + $subject,
50 + $content,
51 + $content_type
52 + );
53 + }
49 54
50 55
51 - /**
52 - * Method send_http_check_notification().
53 - *
54 - * Send HTTP response email notification.
55 - *
56 - * @param mixed $email_settings Email settings.
57 - * @param array $sites_status Websites http status.
58 - * @param bool $plain_text Text format.
59 - *
60 - * @return bool False if failed.
61 - *
62 - * @uses \MainWP\Dashboard\MainWP_Logger::debug()
63 - * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_html()
64 - */
65 - public static function send_http_check_notification( $email_settings, $sites_status, $plain_text ) {
56 + /**
57 + * Method send_http_check_notification().
58 + *
59 + * Send HTTP response email notification.
60 + *
61 + * @param mixed $email_settings Email settings.
62 + * @param array $sites_status Websites http status.
63 + * @param bool $plain_text Text format.
64 + *
65 + * @return bool False if failed.
66 + *
67 + * @uses \MainWP\Dashboard\MainWP_Logger::debug()
68 + * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_html()
69 + */
70 + public static function send_http_check_notification( $email_settings, $sites_status, $plain_text ) {
66 71
67 - if ( $plain_text ) {
68 - $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
69 - } else {
70 - $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
71 - }
72 + if ( $plain_text ) {
73 + $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
74 + } else {
75 + $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
76 + }
72 77
73 - $heading = $email_settings['heading'];
74 - $subject = $email_settings['subject'];
78 + $heading = $email_settings['heading'];
79 + $subject = $email_settings['subject'];
75 80
76 - $formated_content = MainWP_Notification_Template::instance()->get_template_html(
77 - 'emails/mainwp-after-update-http-check-email.php',
78 - array(
79 - 'sites_statuses' => $sites_status,
80 - 'heading' => $heading,
81 - )
82 - );
81 + $formated_content = MainWP_Notification_Template::instance()->get_template_html(
82 + 'emails/mainwp-after-update-http-check-email.php',
83 + array(
84 + 'sites_statuses' => $sites_status,
85 + 'heading' => $heading,
86 + )
87 + );
83 88
84 - $email = '';
89 + $email = '';
85 90
86 - if ( ! empty( $email_settings['recipients'] ) ) {
87 - $email .= ',' . $email_settings['recipients']; // send to recipients.
88 - }
91 + if ( ! empty( $email_settings['recipients'] ) ) {
92 + $email .= ',' . $email_settings['recipients']; // send to recipients.
93 + }
89 94
90 - $email = trim( $email, ',' );
95 + $email = trim( $email, ',' );
91 96
92 - if ( ! empty( $email ) ) {
93 - MainWP_Logger::instance()->debug( 'CRON :: http check :: send mail ::' );
94 - self::send_wp_mail(
95 - $email,
96 - $subject,
97 - $formated_content,
98 - $content_type
99 - );
100 - return true;
101 - }
97 + if ( ! empty( $email ) ) {
98 + MainWP_Logger::instance()->debug( 'http check :: send mail ::' );
99 + static::send_wp_mail(
100 + $email,
101 + $subject,
102 + $formated_content,
103 + $content_type
104 + );
105 + return true;
106 + }
102 107
103 - return false;
104 - }
108 + return false;
109 + }
105 110
106 - /**
107 - * Method send_daily_digest_notification().
108 - *
109 - * Sent available updates notification email.
110 - *
111 - * @param array $email_settings Email settings.
112 - * @param bool $available_updates Update avaiable.
113 - * @param mixed $wp_updates WP updates.
114 - * @param mixed $plugin_updates Plugins updates.
115 - * @param mixed $theme_updates Themes updates.
116 - * @param mixed $sites_disconnected Sites disconnected.
117 - * @param bool $plain_text Text format.
118 - * @param bool $sites_ids Websites ids - default false (option).
119 - * @param bool $email_site current report site.
120 - *
121 - * @return bool
122 - *
123 - * @uses \MainWP\Dashboard\MainWP_Logger::debug()
124 - * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_html()
125 - */
126 - public static function send_daily_digest_notification( $email_settings, $available_updates, $wp_updates, $plugin_updates, $theme_updates, $sites_disconnected, $plain_text, $sites_ids = false, $email_site = false ) {
127 111
128 - if ( $email_settings['disable'] ) {
129 - return false; // disabled send daily digest notification.
130 - }
112 + /**
113 + * Method send_license_deactivated_alert().
114 + *
115 + * Send extensions license deactivated email notification.
116 + *
117 + * @param mixed $email_settings Email settings.
118 + * @param array $deactivated_license Websites http status.
119 + * @param bool $plain_text Text format.
120 + *
121 + * @return bool False if failed.
122 + */
123 + public static function send_license_deactivated_alert( $email_settings, $deactivated_license, $plain_text ) {
131 124
132 - $email = '';
125 + if ( $plain_text ) {
126 + $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
127 + } else {
128 + $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
129 + }
133 130
134 - if ( ! empty( $email_settings['recipients'] ) ) {
135 - $email .= ',' . $email_settings['recipients']; // send to recipients, individual email settings or general email settings.
136 - }
131 + $heading = $email_settings['heading'];
132 + $subject = $email_settings['subject'];
137 133
138 - $email = trim( $email, ',' );
134 + $formated_content = MainWP_Notification_Template::instance()->get_template_html(
135 + 'emails/mainwp-licenses-deactivated-alert-email.php',
136 + array(
137 + 'deactivated_licenses' => $deactivated_license,
138 + 'heading' => $heading,
139 + )
140 + );
139 141
140 - if ( empty( $email ) ) {
141 - return false;
142 - }
142 + $email = '';
143 143
144 - if ( $plain_text ) {
145 - $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
146 - } else {
147 - $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
148 - }
144 + if ( ! empty( $email_settings['recipients'] ) ) {
145 + $email .= ',' . $email_settings['recipients']; // send to recipients.
146 + }
149 147
150 - /**
151 - * Filter: mainwp_daily_digest_content
152 - *
153 - * Filters the Daily Digest email content and adds support for enabling text/plain emails.
154 - *
155 - * @param array $sites_ids Array of sites IDs.
156 - * @param bool $plain_text Wether plain text mode is enabled.
157 - *
158 - * @since 4.1
159 - */
160 - $other_digest = apply_filters( 'mainwp_daily_digest_content', false, $sites_ids, $plain_text );
148 + $email = trim( $email, ',' );
161 149
162 - $heading = $email_settings['heading'];
150 + if ( ! empty( $email ) ) {
151 + MainWP_Logger::instance()->debug( 'license deactivated alert:: send mail ::' );
152 + static::send_wp_mail(
153 + $email,
154 + $subject,
155 + $formated_content,
156 + $content_type
157 + );
158 + return true;
159 + }
163 160
164 - $formated_content = MainWP_Notification_Template::instance()->get_template_html(
165 - 'emails/mainwp-daily-digest-email.php',
166 - array(
167 - 'available_updates' => $available_updates,
168 - 'wp_updates' => $wp_updates,
169 - 'plugin_updates' => $plugin_updates,
170 - 'theme_updates' => $theme_updates,
171 - 'sites_disconnected' => $sites_disconnected,
172 - 'other_digest' => $other_digest,
173 - 'heading' => $heading,
174 - 'current_email_site' => $email_site, // support tokens process.
175 - )
176 - );
161 + return false;
162 + }
177 163
178 - $subject = $email_settings['subject'];
179 - $sent = self::send_wp_mail(
180 - $email,
181 - $subject,
182 - $formated_content,
183 - $content_type
184 - );
185 - if ( $sent ) {
186 - MainWP_Logger::instance()->log_update_check( 'CRON :: daily digest :: send mail :: successful :: ' . $email );
187 - } else {
188 - MainWP_Logger::instance()->log_update_check( 'CRON :: daily digest :: send mail :: failed :: ' . $email );
189 - }
190 - return true;
191 - }
192 164
165 + /**
166 + * Method send_daily_digest_notification().
167 + *
168 + * Sent available updates notification email.
169 + *
170 + * @param array $email_settings Email settings.
171 + * @param bool $available_updates Update avaiable.
172 + * @param mixed $wp_updates WP updates.
173 + * @param mixed $plugin_updates Plugin updates.
174 + * @param mixed $theme_updates Theme updates.
175 + * @param mixed $sites_disconnected Sites disconnected.
176 + * @param array $params Other params.
177 + *
178 + * @return bool
179 + *
180 + * @uses \MainWP\Dashboard\MainWP_Logger::debug()
181 + * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_html()
182 + */
183 + public static function send_daily_digest_notification( $email_settings, $available_updates, $wp_updates, $plugin_updates, $theme_updates, $sites_disconnected, $params = array() ) {
193 184
194 - /**
195 - * Method send_websites_uptime_monitoring().
196 - *
197 - * Send websites status email notification.
198 - *
199 - * @param string $emails notification emails.
200 - * @param string $subject email subject.
201 - * @param string $mail_content email content.
202 - * @param bool $plain_text Text format.
203 - *
204 - * @uses \MainWP\Dashboard\MainWP_Logger::debug()
205 - */
206 - public static function send_websites_uptime_monitoring( $emails, $subject, $mail_content, $plain_text ) {
185 + if ( ! is_array( $params ) ) {
186 + $params = array();
187 + }
207 188
208 - if ( $plain_text ) {
209 - $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
210 - } else {
211 - $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
212 - }
189 + $plain_text = isset( $params['plain_text'] ) ? $params['plain_text'] : '';
190 + $sites_ids = isset( $params['sites_ids'] ) ? $params['sites_ids'] : false;
191 + $email_site = isset( $params['email_site'] ) ? $params['email_site'] : false;
213 192
214 - if ( ! empty( $emails ) && ! empty( $mail_content ) ) {
215 - MainWP_Logger::instance()->debug( 'CRON :: sites status :: send mail ::' );
216 - self::send_wp_mail(
217 - $emails,
218 - $subject,
219 - $mail_content,
220 - $content_type
221 - );
222 - }
223 - }
193 + if ( $email_settings['disable'] ) {
194 + return false; // disabled send daily digest notification.
195 + }
224 196
225 - /**
226 - * Method send_websites_health_status_notification().
227 - *
228 - * Send websites status email notification.
229 - *
230 - * @param string $email notification email.
231 - * @param string $subject subject.
232 - * @param string $mail_content email content.
233 - * @param bool $plain_text Text format.
234 - *
235 - * @uses \MainWP\Dashboard\MainWP_Logger::debug()
236 - */
237 - public static function send_websites_health_status_notification( $email, $subject, $mail_content, $plain_text ) {
197 + $email = '';
238 198
239 - if ( $plain_text ) {
240 - $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
241 - } else {
242 - $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
243 - }
199 + if ( ! empty( $email_settings['recipients'] ) ) {
200 + $email .= ',' . $email_settings['recipients']; // send to recipients, individual email settings or general email settings.
201 + }
244 202
245 - if ( ! empty( $email ) && ! empty( $mail_content ) ) {
246 - MainWP_Logger::instance()->debug( 'CRON :: sites health :: send mail ::' );
247 - self::send_wp_mail(
248 - $email,
249 - $subject,
250 - $mail_content,
251 - $content_type
252 - );
253 - }
254 - }
203 + $email = trim( $email, ',' );
255 204
205 + if ( empty( $email ) ) {
206 + return false;
207 + }
256 208
257 - /**
258 - * Method send_wp_mail().
259 - *
260 - * Send email via wp_mail().
261 - *
262 - * @param string $email send to email.
263 - * @param string $subject email content.
264 - * @param bool $mail_content Text format.
265 - * @param string $content_type email content.
266 - */
267 - public static function send_wp_mail( $email, $subject, $mail_content, $content_type = '' ) {
268 - if ( empty( $content_type ) ) {
269 - $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
270 - }
209 + if ( $plain_text ) {
210 + $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
211 + } else {
212 + $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
213 + }
271 214
272 - $from_header = array(
273 - 'from_name' => get_option( 'admin_email' ),
274 - 'from_email' => get_option( 'admin_email' ),
275 - );
215 + /**
216 + * Filter: mainwp_daily_digest_content
217 + *
218 + * Filters the Daily Digest email content and adds support for enabling text/plain emails.
219 + *
220 + * @param array $sites_ids Array of sites IDs.
221 + * @param bool $plain_text Wether plain text mode is enabled.
222 + *
223 + * @since 4.1
224 + */
225 + $other_digest = apply_filters( 'mainwp_daily_digest_content', false, $sites_ids, $plain_text );
276 226
277 - $custom_header = apply_filters( 'mainwp_send_mail_from_header', false, $email, $subject );
278 - if ( is_array( $custom_header ) && isset( $custom_header['from_name'] ) && isset( $custom_header['from_email'] ) && ! empty( $custom_header['from_name'] ) && ! empty( $custom_header['from_email'] ) ) {
279 - $from_header = $custom_header;
280 - }
227 + $heading = $email_settings['heading'];
281 228
282 - return wp_mail(
283 - $email,
284 - $subject,
285 - $mail_content,
286 - array(
287 - 'From: "' . $from_header['from_name'] . '" <' . $from_header['from_email'] . '>',
288 - $content_type,
289 - )
290 - );
291 - }
229 + $formated_content = MainWP_Notification_Template::instance()->get_template_html(
230 + 'emails/mainwp-daily-digest-email.php',
231 + array(
232 + 'available_updates' => $available_updates,
233 + 'wp_updates' => $wp_updates,
234 + 'plugin_updates' => $plugin_updates,
235 + 'theme_updates' => $theme_updates,
236 + 'sites_disconnected' => $sites_disconnected,
237 + 'other_digest' => $other_digest,
238 + 'heading' => $heading,
239 + 'current_email_site' => $email_site, // support tokens process.
240 + )
241 + );
242 +
243 + $subject = $email_settings['subject'];
244 + $sent = static::send_wp_mail(
245 + $email,
246 + $subject,
247 + $formated_content,
248 + $content_type
249 + );
250 + if ( $sent ) {
251 + MainWP_Logger::instance()->log_update_check( 'daily digest :: send mail :: successful :: ' . $email );
252 + } else {
253 + MainWP_Logger::instance()->log_update_check( 'daily digest :: send mail :: failed :: ' . $email );
254 + }
255 + return true;
256 + }
257 +
258 +
259 + /**
260 + * Method send_websites_uptime_monitoring().
261 + *
262 + * Send websites status email notification.
263 + *
264 + * @param string $emails notification emails.
265 + * @param string $subject email subject.
266 + * @param string $mail_content email content.
267 + * @param bool $plain_text Text format.
268 + * @param object $site_mo Monitor website.
269 + *
270 + * @uses \MainWP\Dashboard\MainWP_Logger::debug()
271 + */
272 + public static function send_websites_uptime_monitoring( $emails, $subject, $mail_content, $plain_text, $site_mo = false ) {
273 +
274 + if ( $plain_text ) {
275 + $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
276 + } else {
277 + $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
278 + }
279 +
280 + if ( ! empty( $emails ) && ! empty( $mail_content ) ) {
281 + MainWP_Logger::instance()->log_uptime_notice( 'Uptime monitoring status :: send mail :: ' . $subject );
282 + if ( $site_mo ) {
283 + $event_time = ! empty( $site_mo->hb_time_check ) ? gmdate( 'Y-m-d H:i:s', $site_mo->hb_time_check ) : '';
284 + MainWP_Logger::instance()->log_uptime_notice( 'Sending notification :: [subject=' . esc_html( $subject ) . '] :: [event-time=' . $event_time . '] :: [monitorid=' . $site_mo->monitor_id . '] :: [monitor-url=' . ( empty( $site_mo->issub ) ? $site_mo->url : $site_mo->suburl ) . ']' );
285 + }
286 + static::send_wp_mail(
287 + $emails,
288 + $subject,
289 + $mail_content,
290 + $content_type,
291 + $site_mo
292 + );
293 + }
294 + }
295 +
296 + /**
297 + * Method send_websites_health_status_notification().
298 + *
299 + * Send websites status email notification.
300 + *
301 + * @param string $email notification email.
302 + * @param string $subject subject.
303 + * @param string $mail_content email content.
304 + * @param bool $plain_text Text format.
305 + *
306 + * @uses \MainWP\Dashboard\MainWP_Logger::debug()
307 + */
308 + public static function send_websites_health_status_notification( $email, $subject, $mail_content, $plain_text ) {
309 +
310 + if ( $plain_text ) {
311 + $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
312 + } else {
313 + $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
314 + }
315 +
316 + if ( ! empty( $email ) && ! empty( $mail_content ) ) {
317 + MainWP_Logger::instance()->debug( 'sites health :: send mail ::' );
318 + static::send_wp_mail(
319 + $email,
320 + $subject,
321 + $mail_content,
322 + $content_type
323 + );
324 + }
325 + }
326 +
327 +
328 + /**
329 + * Start notification for auto update info.
330 + *
331 + * @param array $admin_email_settings Admin email settings.
332 + * @param array $params Parameters for the notification.
333 + *
334 + * @return void
335 + */
336 + public static function start_notification_auto_updates_info( $admin_email_settings, $params = array() ) {
337 +
338 + $email = isset( $admin_email_settings['recipients'] ) ? $admin_email_settings['recipients'] : '';
339 + $subject = isset( $admin_email_settings['subject'] ) ? $admin_email_settings['subject'] : '';
340 + $plain_text = isset( $params['plain_text'] ) ? $params['plain_text'] : false;
341 + $mail_content = isset( $params['mail_content'] ) ? $params['mail_content'] : '';
342 +
343 + if ( $plain_text ) {
344 + $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
345 + } else {
346 + $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
347 + }
348 +
349 + if ( ! empty( $email ) && ! empty( $mail_content ) ) {
350 + MainWP_Logger::instance()->log_events( 'auto-updates', 'Auto updates notification :: send mail' );
351 + static::send_wp_mail(
352 + $email,
353 + $subject,
354 + $mail_content,
355 + $content_type
356 + );
357 + }
358 + }
359 +
360 +
361 + /**
362 + * Method send_wp_mail().
363 + *
364 + * Send email via wp_mail().
365 + *
366 + * @param string $email send to email.
367 + * @param string $subject email content.
368 + * @param string $mail_content Text format.
369 + * @param string $content_type email content.
370 + * @param mixed $object_sending Optional object associated with the email being sent.
371 + */
372 + public static function send_wp_mail( $email, $subject, $mail_content, $content_type = '', $object_sending = null ) {
373 + if ( empty( $content_type ) ) {
374 + $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
375 + }
376 +
377 + $from_header = array(
378 + 'from_name' => get_option( 'admin_email' ),
379 + 'from_email' => get_option( 'admin_email' ),
380 + );
381 +
382 + $custom_header = apply_filters( 'mainwp_send_mail_from_header', false, $email, $subject );
383 + if ( is_array( $custom_header ) && isset( $custom_header['from_name'] ) && isset( $custom_header['from_email'] ) && ! empty( $custom_header['from_name'] ) && ! empty( $custom_header['from_email'] ) ) {
384 + $from_header = $custom_header;
385 + }
386 +
387 + /**
388 + * Fires before an email is sent via wp_mail().
389 + *
390 + * @since 6.1.6
391 + *
392 + * @param string $email Recipient email address.
393 + * @param string $subject Email subject.
394 + * @param string $mail_content Email message content.
395 + * @param string $content_type Email content type.
396 + * @param object|mixed $object_sending Object associated with the email being sent.
397 + */
398 + $email = apply_filters(
399 + 'mainwp_wp_mail_to',
400 + $email,
401 + $subject,
402 + $mail_content,
403 + $content_type,
404 + $object_sending
405 + );
406 +
407 + if ( empty( $email ) ) {
408 + // stop send.
409 + return false;
410 + }
411 +
412 + return wp_mail(
413 + $email,
414 + $subject,
415 + $mail_content,
416 + array(
417 + 'From: "' . $from_header['from_name'] . '" <' . $from_header['from_email'] . '>',
418 + $content_type,
419 + )
420 + );
421 + }
292 422 }