PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.3
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 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-notification.php

class-mainwp-notification.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.0.3, at class/class-mainwp-notification.php

347 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Notification
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Notification
12 *
13 * @package MainWP\Dashboard
14 */
15 class MainWP_Notification {
16
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 }
27
28
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 }
49
50
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 ) {
66
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
73 $heading = $email_settings['heading'];
74 $subject = $email_settings['subject'];
75
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 );
83
84 $email = '';
85
86 if ( ! empty( $email_settings['recipients'] ) ) {
87 $email .= ',' . $email_settings['recipients']; // send to recipients.
88 }
89
90 $email = trim( $email, ',' );
91
92 if ( ! empty( $email ) ) {
93 MainWP_Logger::instance()->debug( 'http check :: send mail ::' );
94 self::send_wp_mail(
95 $email,
96 $subject,
97 $formated_content,
98 $content_type
99 );
100 return true;
101 }
102
103 return false;
104 }
105
106
107 /**
108 * Method send_license_deactivated_alert().
109 *
110 * Send extensions license deactivated email notification.
111 *
112 * @param mixed $email_settings Email settings.
113 * @param array $deactivated_license Websites http status.
114 * @param bool $plain_text Text format.
115 *
116 * @return bool False if failed.
117 */
118 public static function send_license_deactivated_alert( $email_settings, $deactivated_license, $plain_text ) {
119
120 if ( $plain_text ) {
121 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
122 } else {
123 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
124 }
125
126 $heading = $email_settings['heading'];
127 $subject = $email_settings['subject'];
128
129 $formated_content = MainWP_Notification_Template::instance()->get_template_html(
130 'emails/mainwp-licenses-deactivated-alert-email.php',
131 array(
132 'deactivated_licenses' => $deactivated_license,
133 'heading' => $heading,
134 )
135 );
136
137 $email = '';
138
139 if ( ! empty( $email_settings['recipients'] ) ) {
140 $email .= ',' . $email_settings['recipients']; // send to recipients.
141 }
142
143 $email = trim( $email, ',' );
144
145 if ( ! empty( $email ) ) {
146 MainWP_Logger::instance()->debug( 'license deactivated alert:: send mail ::' );
147 self::send_wp_mail(
148 $email,
149 $subject,
150 $formated_content,
151 $content_type
152 );
153 return true;
154 }
155
156 return false;
157 }
158
159
160 /**
161 * Method send_daily_digest_notification().
162 *
163 * Sent available updates notification email.
164 *
165 * @param array $email_settings Email settings.
166 * @param bool $available_updates Update avaiable.
167 * @param mixed $wp_updates WP updates.
168 * @param mixed $plugin_updates Plugins updates.
169 * @param mixed $theme_updates Themes updates.
170 * @param mixed $sites_disconnected Sites disconnected.
171 * @param bool $plain_text Text format.
172 * @param bool $sites_ids Websites ids - default false (option).
173 * @param bool $email_site current report site.
174 *
175 * @return bool
176 *
177 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
178 * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_html()
179 */
180 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 ) {
181
182 if ( $email_settings['disable'] ) {
183 return false; // disabled send daily digest notification.
184 }
185
186 $email = '';
187
188 if ( ! empty( $email_settings['recipients'] ) ) {
189 $email .= ',' . $email_settings['recipients']; // send to recipients, individual email settings or general email settings.
190 }
191
192 $email = trim( $email, ',' );
193
194 if ( empty( $email ) ) {
195 return false;
196 }
197
198 if ( $plain_text ) {
199 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
200 } else {
201 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
202 }
203
204 /**
205 * Filter: mainwp_daily_digest_content
206 *
207 * Filters the Daily Digest email content and adds support for enabling text/plain emails.
208 *
209 * @param array $sites_ids Array of sites IDs.
210 * @param bool $plain_text Wether plain text mode is enabled.
211 *
212 * @since 4.1
213 */
214 $other_digest = apply_filters( 'mainwp_daily_digest_content', false, $sites_ids, $plain_text );
215
216 $heading = $email_settings['heading'];
217
218 $formated_content = MainWP_Notification_Template::instance()->get_template_html(
219 'emails/mainwp-daily-digest-email.php',
220 array(
221 'available_updates' => $available_updates,
222 'wp_updates' => $wp_updates,
223 'plugin_updates' => $plugin_updates,
224 'theme_updates' => $theme_updates,
225 'sites_disconnected' => $sites_disconnected,
226 'other_digest' => $other_digest,
227 'heading' => $heading,
228 'current_email_site' => $email_site, // support tokens process.
229 )
230 );
231
232 $subject = $email_settings['subject'];
233 $sent = self::send_wp_mail(
234 $email,
235 $subject,
236 $formated_content,
237 $content_type
238 );
239 if ( $sent ) {
240 MainWP_Logger::instance()->log_update_check( 'daily digest :: send mail :: successful :: ' . $email );
241 } else {
242 MainWP_Logger::instance()->log_update_check( 'daily digest :: send mail :: failed :: ' . $email );
243 }
244 return true;
245 }
246
247
248 /**
249 * Method send_websites_uptime_monitoring().
250 *
251 * Send websites status email notification.
252 *
253 * @param string $emails notification emails.
254 * @param string $subject email subject.
255 * @param string $mail_content email content.
256 * @param bool $plain_text Text format.
257 *
258 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
259 */
260 public static function send_websites_uptime_monitoring( $emails, $subject, $mail_content, $plain_text ) {
261
262 if ( $plain_text ) {
263 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
264 } else {
265 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
266 }
267
268 if ( ! empty( $emails ) && ! empty( $mail_content ) ) {
269 MainWP_Logger::instance()->debug( 'sites status :: send mail ::' );
270 self::send_wp_mail(
271 $emails,
272 $subject,
273 $mail_content,
274 $content_type
275 );
276 }
277 }
278
279 /**
280 * Method send_websites_health_status_notification().
281 *
282 * Send websites status email notification.
283 *
284 * @param string $email notification email.
285 * @param string $subject subject.
286 * @param string $mail_content email content.
287 * @param bool $plain_text Text format.
288 *
289 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
290 */
291 public static function send_websites_health_status_notification( $email, $subject, $mail_content, $plain_text ) {
292
293 if ( $plain_text ) {
294 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
295 } else {
296 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
297 }
298
299 if ( ! empty( $email ) && ! empty( $mail_content ) ) {
300 MainWP_Logger::instance()->debug( 'sites health :: send mail ::' );
301 self::send_wp_mail(
302 $email,
303 $subject,
304 $mail_content,
305 $content_type
306 );
307 }
308 }
309
310
311 /**
312 * Method send_wp_mail().
313 *
314 * Send email via wp_mail().
315 *
316 * @param string $email send to email.
317 * @param string $subject email content.
318 * @param bool $mail_content Text format.
319 * @param string $content_type email content.
320 */
321 public static function send_wp_mail( $email, $subject, $mail_content, $content_type = '' ) {
322 if ( empty( $content_type ) ) {
323 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
324 }
325
326 $from_header = array(
327 'from_name' => get_option( 'admin_email' ),
328 'from_email' => get_option( 'admin_email' ),
329 );
330
331 $custom_header = apply_filters( 'mainwp_send_mail_from_header', false, $email, $subject );
332 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'] ) ) {
333 $from_header = $custom_header;
334 }
335
336 return wp_mail(
337 $email,
338 $subject,
339 $mail_content,
340 array(
341 'From: "' . $from_header['from_name'] . '" <' . $from_header['from_email'] . '>',
342 $content_type,
343 )
344 );
345 }
346 }
347