| @@ -6,8 +6,13 @@ | ||
| 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 |
| @@ -259,12 +264,13 @@ | ||
| 259 | 264 | * @param string $emails notification emails. |
| 260 | 265 | * @param string $subject email subject. |
| 261 | 266 | * @param string $mail_content email content. |
| 262 | 267 | * @param bool $plain_text Text format. |
| 268 | + * @param object $site_mo Monitor website. | |
| 263 | 269 | * |
| 264 | 270 | * @uses \MainWP\Dashboard\MainWP_Logger::debug() |
| 265 | 271 | */ |
| 266 | - public static function send_websites_uptime_monitoring( $emails, $subject, $mail_content, $plain_text ) { | |
| 272 | + public static function send_websites_uptime_monitoring( $emails, $subject, $mail_content, $plain_text, $site_mo = false ) { | |
| 267 | 273 | |
| 268 | 274 | if ( $plain_text ) { |
| 269 | 275 | $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n"; |
| 270 | 276 | } else { |
| @@ -271,14 +277,19 @@ | ||
| 271 | 277 | $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n"; |
| 272 | 278 | } |
| 273 | 279 | |
| 274 | 280 | if ( ! empty( $emails ) && ! empty( $mail_content ) ) { |
| 275 | - MainWP_Logger::instance()->debug( 'Uptime monitoring status :: send mail ::' ); | |
| 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 | + } | |
| 276 | 286 | static::send_wp_mail( |
| 277 | 287 | $emails, |
| 278 | 288 | $subject, |
| 279 | 289 | $mail_content, |
| 280 | - $content_type | |
| 290 | + $content_type, | |
| 291 | + $site_mo | |
| 281 | 292 | ); |
| 282 | 293 | } |
| 283 | 294 | } |
| 284 | 295 | |
| @@ -314,8 +325,41 @@ | ||
| 314 | 325 | } |
| 315 | 326 | |
| 316 | 327 | |
| 317 | 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 | + /** | |
| 318 | 362 | * Method send_wp_mail(). |
| 319 | 363 | * |
| 320 | 364 | * Send email via wp_mail(). |
| 321 | 365 | * |
| @@ -322,10 +366,11 @@ | ||
| 322 | 366 | * @param string $email send to email. |
| 323 | 367 | * @param string $subject email content. |
| 324 | 368 | * @param string $mail_content Text format. |
| 325 | 369 | * @param string $content_type email content. |
| 370 | + * @param mixed $object_sending Optional object associated with the email being sent. | |
| 326 | 371 | */ |
| 327 | - public static function send_wp_mail( $email, $subject, $mail_content, $content_type = '' ) { | |
| 372 | + public static function send_wp_mail( $email, $subject, $mail_content, $content_type = '', $object_sending = null ) { | |
| 328 | 373 | if ( empty( $content_type ) ) { |
| 329 | 374 | $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n"; |
| 330 | 375 | } |
| 331 | 376 | |
| @@ -336,8 +381,33 @@ | ||
| 336 | 381 | |
| 337 | 382 | $custom_header = apply_filters( 'mainwp_send_mail_from_header', false, $email, $subject ); |
| 338 | 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'] ) ) { |
| 339 | 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; | |
| 340 | 410 | } |
| 341 | 411 | |
| 342 | 412 | return wp_mail( |
| 343 | 413 | $email, |