3429a884 by Jeff Balicki

admin notifications

1 parent b91a8ab1
...@@ -515,6 +515,95 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = ...@@ -515,6 +515,95 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
515 } 515 }
516 } 516 }
517 517
518 function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $args = [])
519 {
520
521 $lang = 'en';
522
523 /** @var \StdClass $notification */
524 $notification = get_notification_by_trigger($trigger);
525
526 if ($notification) {
527 // get the notification and notificatio details....
528 $nid = $notification->ID;
529 $details = get_post_meta($nid, 'details', true);
530 $email = get_post_meta($nid, 'email', true);
531 $system = get_post_meta($nid, 'system', true);
532
533 $notification->trigger = $details['trigger'];
534 $notification->status = isset($details['status']) ? $details['status'] : 'active';
535 $notification->type = $details['type'];
536 $notification->sendto = @$details['sendto'];
537 $notification->is_email = (($email[$lang.'_text'] != '' || $email[$lang.'_html'] != '') && $email[$lang.'_subject'] != '');
538 $notification->is_system = (isset($system[$lang.'_message']) && $system[$lang.'_message'] != '');
539
540 // if is_system ==========================================
541 if ($notification->is_system && $uid != 0) {
542 get_user_notices($uid);
543 $notices = Vars::$notices;
544
545 // Add a system message into the usermeta as well to track the system notification.
546 $insert = [
547 'notification_id' => $nid,
548 'status' => 'unread',
549 'sent_date' => current_time('timestamp'),
550 'message' => $system[$lang.'_message'],
551 'args' => $args
552 ];
553 }
554
555
556 }
557
558 $contents = $email;
559
560 $fromEmail = get_bloginfo('admin_email');
561 $subject = strip_tags(
562 isset($contents[$lang.'_subject']) && !empty($contents[$lang.'_subject'])
563 ? $contents[$lang.'_subject']
564 : $contents['en_subject']
565 );
566 $html = isset($contents[$lang.'_html']) && !empty($contents[$lang.'_html'])
567 ? $contents[$lang.'_html']
568 : @$contents['en_html'];
569 $altText = strip_tags(
570 isset($contents[$lang.'_text']) && !empty($contents[$lang.'_text'])
571 ? $contents[$lang.'_text']
572 : $contents['en_text']
573 );
574
575 foreach ($args as $key => $val) {
576 if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) {
577 $html = str_replace('{'.$key.'}', '<a href="'.$val.'">'.$val.'</a>', $html);
578 } else {
579 $html = str_replace('{'.$key.'}', $val, $html);
580 $altText = str_replace('{'.$key.'}', $val, $altText);
581 $subject = str_replace('{'.$key.'}', $val, $subject);
582 }
583 }
584
585
586
587
588
589
590
591 $sentSuccessfully = false;
592 if (CBV\system_can_send_emails_using_wpdb()) {
593 $response = \wpMandrill::mail($toEmail, $subject, !empty($html) ? $html : $altText, [], $attachments);
594 if (
595 is_array($response)
596 && isset($response[0]['status'])
597 && isset($response[0]['status'])
598 && !in_array($response['status'], ['rejected', 'invalid'])
599 ) {
600 $sentSuccessfully = true;
601 }
602 }
603
604
605 }
606
518 /** 607 /**
519 * @param int $grpID 608 * @param int $grpID
520 * 609 *
......