PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.4.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.4.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 4.4.1, at class/class-mainwp-notification.php

295 lines 8.0 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 * @param bool $general Either general or individual notification.
60 *
61 * @return bool False if failed.
62 *
63 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
64 * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_html()
65 */
66 public static function send_http_check_notification( $email_settings, $sites_status, $plain_text, $general = true ) {
67
68 if ( $plain_text ) {
69 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
70 } else {
71 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
72 }
73
74 $heading = $email_settings['heading'];
75 $subject = $email_settings['subject'];
76
77 $formated_content = MainWP_Notification_Template::instance()->get_template_html(
78 'emails/mainwp-after-update-http-check-email.php',
79 array(
80 'sites_statuses' => $sites_status,
81 'heading' => $heading,
82 )
83 );
84
85 $email = '';
86
87 if ( ! empty( $email_settings['recipients'] ) ) {
88 $email .= ',' . $email_settings['recipients']; // send to recipients.
89 }
90
91 $email = trim( $email, ',' );
92
93 if ( ! empty( $email ) ) {
94 MainWP_Logger::instance()->debug( 'CRON :: http check :: send mail ::' );
95 self::send_wp_mail(
96 $email,
97 $subject,
98 $formated_content,
99 $content_type
100 );
101 return true;
102 }
103
104 return false;
105 }
106
107 /**
108 * Method send_daily_digest_notification().
109 *
110 * Sent available updates notification email.
111 *
112 * @param array $email_settings Email settings.
113 * @param bool $available_updates Update avaiable.
114 * @param mixed $wp_updates WP updates.
115 * @param mixed $plugin_updates Plugins updates.
116 * @param mixed $theme_updates Themes updates.
117 * @param mixed $sites_disconnected Sites disconnected.
118 * @param bool $plain_text Text format.
119 * @param bool $sites_ids Websites ids - default false (option).
120 * @param bool $email_site current report site.
121 *
122 * @return bool
123 *
124 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
125 * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_html()
126 */
127 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 ) {
128
129 if ( $email_settings['disable'] ) {
130 return false; // disabled send daily digest notification.
131 }
132
133 $email = '';
134
135 if ( ! empty( $email_settings['recipients'] ) ) {
136 $email .= ',' . $email_settings['recipients']; // send to recipients, individual email settings or general email settings.
137 }
138
139 $email = trim( $email, ',' );
140
141 if ( empty( $email ) ) {
142 return false;
143 }
144
145 if ( $plain_text ) {
146 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
147 } else {
148 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
149 }
150
151 /**
152 * Filter: mainwp_daily_digest_content
153 *
154 * Filters the Daily Digest email content and adds support for enabling text/plain emails.
155 *
156 * @param array $sites_ids Array of sites IDs.
157 * @param bool $plain_text Wether plain text mode is enabled.
158 *
159 * @since 4.1
160 */
161 $other_digest = apply_filters( 'mainwp_daily_digest_content', false, $sites_ids, $plain_text );
162
163 $heading = $email_settings['heading'];
164
165 $formated_content = MainWP_Notification_Template::instance()->get_template_html(
166 'emails/mainwp-daily-digest-email.php',
167 array(
168 'available_updates' => $available_updates,
169 'wp_updates' => $wp_updates,
170 'plugin_updates' => $plugin_updates,
171 'theme_updates' => $theme_updates,
172 'sites_disconnected' => $sites_disconnected,
173 'other_digest' => $other_digest,
174 'heading' => $heading,
175 'current_email_site' => $email_site, // support tokens process.
176 )
177 );
178
179 $subject = $email_settings['subject'];
180 $sent = self::send_wp_mail(
181 $email,
182 $subject,
183 $formated_content,
184 $content_type
185 );
186 if ( $sent ) {
187 MainWP_Logger::instance()->log_update_check( 'CRON :: daily digest :: send mail :: successful :: ' . $email );
188 } else {
189 MainWP_Logger::instance()->log_update_check( 'CRON :: daily digest :: send mail :: failed :: ' . $email );
190 }
191 return true;
192 }
193
194
195 /**
196 * Method send_websites_uptime_monitoring().
197 *
198 * Send websites status email notification.
199 *
200 * @param string $emails notification emails.
201 * @param string $subject email subject.
202 * @param string $mail_content email content.
203 * @param bool $plain_text Text format.
204 *
205 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
206 */
207 public static function send_websites_uptime_monitoring( $emails, $subject, $mail_content, $plain_text ) {
208
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 }
214
215 if ( ! empty( $emails ) && '' != $mail_content ) {
216 MainWP_Logger::instance()->debug( 'CRON :: sites status :: send mail ::' );
217 self::send_wp_mail(
218 $emails,
219 $subject,
220 $mail_content,
221 $content_type
222 );
223 }
224 }
225
226 /**
227 * Method send_websites_health_status_notification().
228 *
229 * Send websites status email notification.
230 *
231 * @param string $email notification email.
232 * @param string $subject subject.
233 * @param string $mail_content email content.
234 * @param bool $plain_text Text format.
235 *
236 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
237 */
238 public static function send_websites_health_status_notification( $email, $subject, $mail_content, $plain_text ) {
239
240 if ( $plain_text ) {
241 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
242 } else {
243 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
244 }
245
246 if ( ! empty( $email ) && '' != $mail_content ) {
247 MainWP_Logger::instance()->debug( 'CRON :: sites health :: send mail ::' );
248 self::send_wp_mail(
249 $email,
250 $subject,
251 $mail_content,
252 $content_type
253 );
254 }
255 }
256
257
258 /**
259 * Method send_wp_mail().
260 *
261 * Send email via wp_mail().
262 *
263 * @param string $email send to email.
264 * @param string $subject email content.
265 * @param bool $mail_content Text format.
266 * @param string $content_type email content.
267 */
268 public static function send_wp_mail( $email, $subject, $mail_content, $content_type = '' ) {
269 if ( empty( $content_type ) ) {
270 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
271 }
272
273 $from_header = array(
274 'from_name' => get_option( 'admin_email' ),
275 'from_email' => get_option( 'admin_email' ),
276 );
277
278 $custom_header = apply_filters( 'mainwp_send_mail_from_header', false, $email, $subject );
279 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'] ) ) {
280 $from_header = $custom_header;
281 }
282
283 return wp_mail(
284 $email,
285 $subject,
286 $mail_content,
287 array(
288 'From: "' . $from_header['from_name'] . '" <' . $from_header['from_email'] . '>',
289 $content_type,
290 )
291 );
292 }
293
294 }
295