PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.1.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.1.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 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.1.1, at class/class-mainwp-notification.php

353 lines 11.1 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 { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
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 static::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 static::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 static::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 array $params Other params.
172 *
173 * @return bool
174 *
175 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
176 * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_html()
177 */
178 public static function send_daily_digest_notification( $email_settings, $available_updates, $wp_updates, $plugin_updates, $theme_updates, $sites_disconnected, $params = array() ) {
179
180 if ( ! is_array( $params ) ) {
181 $params = array();
182 }
183
184 $plain_text = isset( $params['plain_text'] ) ? $params['plain_text'] : '';
185 $sites_ids = isset( $params['sites_ids'] ) ? $params['sites_ids'] : false;
186 $email_site = isset( $params['email_site'] ) ? $params['email_site'] : false;
187
188 if ( $email_settings['disable'] ) {
189 return false; // disabled send daily digest notification.
190 }
191
192 $email = '';
193
194 if ( ! empty( $email_settings['recipients'] ) ) {
195 $email .= ',' . $email_settings['recipients']; // send to recipients, individual email settings or general email settings.
196 }
197
198 $email = trim( $email, ',' );
199
200 if ( empty( $email ) ) {
201 return false;
202 }
203
204 if ( $plain_text ) {
205 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
206 } else {
207 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
208 }
209
210 /**
211 * Filter: mainwp_daily_digest_content
212 *
213 * Filters the Daily Digest email content and adds support for enabling text/plain emails.
214 *
215 * @param array $sites_ids Array of sites IDs.
216 * @param bool $plain_text Wether plain text mode is enabled.
217 *
218 * @since 4.1
219 */
220 $other_digest = apply_filters( 'mainwp_daily_digest_content', false, $sites_ids, $plain_text );
221
222 $heading = $email_settings['heading'];
223
224 $formated_content = MainWP_Notification_Template::instance()->get_template_html(
225 'emails/mainwp-daily-digest-email.php',
226 array(
227 'available_updates' => $available_updates,
228 'wp_updates' => $wp_updates,
229 'plugin_updates' => $plugin_updates,
230 'theme_updates' => $theme_updates,
231 'sites_disconnected' => $sites_disconnected,
232 'other_digest' => $other_digest,
233 'heading' => $heading,
234 'current_email_site' => $email_site, // support tokens process.
235 )
236 );
237
238 $subject = $email_settings['subject'];
239 $sent = static::send_wp_mail(
240 $email,
241 $subject,
242 $formated_content,
243 $content_type
244 );
245 if ( $sent ) {
246 MainWP_Logger::instance()->log_update_check( 'daily digest :: send mail :: successful :: ' . $email );
247 } else {
248 MainWP_Logger::instance()->log_update_check( 'daily digest :: send mail :: failed :: ' . $email );
249 }
250 return true;
251 }
252
253
254 /**
255 * Method send_websites_uptime_monitoring().
256 *
257 * Send websites status email notification.
258 *
259 * @param string $emails notification emails.
260 * @param string $subject email subject.
261 * @param string $mail_content email content.
262 * @param bool $plain_text Text format.
263 *
264 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
265 */
266 public static function send_websites_uptime_monitoring( $emails, $subject, $mail_content, $plain_text ) {
267
268 if ( $plain_text ) {
269 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
270 } else {
271 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
272 }
273
274 if ( ! empty( $emails ) && ! empty( $mail_content ) ) {
275 MainWP_Logger::instance()->debug( 'sites status :: send mail ::' );
276 static::send_wp_mail(
277 $emails,
278 $subject,
279 $mail_content,
280 $content_type
281 );
282 }
283 }
284
285 /**
286 * Method send_websites_health_status_notification().
287 *
288 * Send websites status email notification.
289 *
290 * @param string $email notification email.
291 * @param string $subject subject.
292 * @param string $mail_content email content.
293 * @param bool $plain_text Text format.
294 *
295 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
296 */
297 public static function send_websites_health_status_notification( $email, $subject, $mail_content, $plain_text ) {
298
299 if ( $plain_text ) {
300 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
301 } else {
302 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
303 }
304
305 if ( ! empty( $email ) && ! empty( $mail_content ) ) {
306 MainWP_Logger::instance()->debug( 'sites health :: send mail ::' );
307 static::send_wp_mail(
308 $email,
309 $subject,
310 $mail_content,
311 $content_type
312 );
313 }
314 }
315
316
317 /**
318 * Method send_wp_mail().
319 *
320 * Send email via wp_mail().
321 *
322 * @param string $email send to email.
323 * @param string $subject email content.
324 * @param bool $mail_content Text format.
325 * @param string $content_type email content.
326 */
327 public static function send_wp_mail( $email, $subject, $mail_content, $content_type = '' ) {
328 if ( empty( $content_type ) ) {
329 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
330 }
331
332 $from_header = array(
333 'from_name' => get_option( 'admin_email' ),
334 'from_email' => get_option( 'admin_email' ),
335 );
336
337 $custom_header = apply_filters( 'mainwp_send_mail_from_header', false, $email, $subject );
338 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'] ) ) {
339 $from_header = $custom_header;
340 }
341
342 return wp_mail(
343 $email,
344 $subject,
345 $mail_content,
346 array(
347 'From: "' . $from_header['from_name'] . '" <' . $from_header['from_email'] . '>',
348 $content_type,
349 )
350 );
351 }
352 }
353