3429a884 by Jeff Balicki

admin notifications

1 parent b91a8ab1
......@@ -23,7 +23,7 @@ call_user_func(
}
}
);
/**
* @param $a
* @param $subkey
......@@ -515,6 +515,95 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
}
}
function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $args = [])
{
$lang = 'en';
/** @var \StdClass $notification */
$notification = get_notification_by_trigger($trigger);
if ($notification) {
// get the notification and notificatio details....
$nid = $notification->ID;
$details = get_post_meta($nid, 'details', true);
$email = get_post_meta($nid, 'email', true);
$system = get_post_meta($nid, 'system', true);
$notification->trigger = $details['trigger'];
$notification->status = isset($details['status']) ? $details['status'] : 'active';
$notification->type = $details['type'];
$notification->sendto = @$details['sendto'];
$notification->is_email = (($email[$lang.'_text'] != '' || $email[$lang.'_html'] != '') && $email[$lang.'_subject'] != '');
$notification->is_system = (isset($system[$lang.'_message']) && $system[$lang.'_message'] != '');
// if is_system ==========================================
if ($notification->is_system && $uid != 0) {
get_user_notices($uid);
$notices = Vars::$notices;
// Add a system message into the usermeta as well to track the system notification.
$insert = [
'notification_id' => $nid,
'status' => 'unread',
'sent_date' => current_time('timestamp'),
'message' => $system[$lang.'_message'],
'args' => $args
];
}
}
$contents = $email;
$fromEmail = get_bloginfo('admin_email');
$subject = strip_tags(
isset($contents[$lang.'_subject']) && !empty($contents[$lang.'_subject'])
? $contents[$lang.'_subject']
: $contents['en_subject']
);
$html = isset($contents[$lang.'_html']) && !empty($contents[$lang.'_html'])
? $contents[$lang.'_html']
: @$contents['en_html'];
$altText = strip_tags(
isset($contents[$lang.'_text']) && !empty($contents[$lang.'_text'])
? $contents[$lang.'_text']
: $contents['en_text']
);
foreach ($args as $key => $val) {
if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) {
$html = str_replace('{'.$key.'}', '<a href="'.$val.'">'.$val.'</a>', $html);
} else {
$html = str_replace('{'.$key.'}', $val, $html);
$altText = str_replace('{'.$key.'}', $val, $altText);
$subject = str_replace('{'.$key.'}', $val, $subject);
}
}
$sentSuccessfully = false;
if (CBV\system_can_send_emails_using_wpdb()) {
$response = \wpMandrill::mail($toEmail, $subject, !empty($html) ? $html : $altText, [], $attachments);
if (
is_array($response)
&& isset($response[0]['status'])
&& isset($response[0]['status'])
&& !in_array($response['status'], ['rejected', 'invalid'])
) {
$sentSuccessfully = true;
}
}
}
/**
* @param int $grpID
*
......