37b90785 by Kevin Burton

updated Notification to use daemon system for email notifications under system triggered.

1 parent a7dd9328
......@@ -188,6 +188,7 @@ function remove_notice($notification_id = -1) {
@trigger = notification unique slug name
*/
function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array(),$send_override = false) {
global $wpdb;
$notification = get_notification_by_trigger($trigger);
if($notification) {
......@@ -229,7 +230,51 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array(),
// if is_email ===========================================
if ($notification->is_email) {
send_email($uid,$email,$args, true);
$user = new User\Account($uid);
$email_address_preference = get_user_meta($user->ID, 'email_address_preference', true);
if (empty($email_address_preference)) {
$to_email = $user->user_email;
} else {
$pp = strtolower($email_address_preference)."_";
$to_email = get_user_meta($user->ID, $pp.'email', true);
if (empty($to_email)) {
$to_email = $user->user_email;
}
}
$contents = $email;
$from_email = get_bloginfo('admin_email');
$subject = strip_tags($contents['subject']);
$html = $contents['html'];
$alttext = strip_tags($contents['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);
}
}
$attachments = array();
if (isset($contents['attachments'])) {
$attachments = $contents['attachments'];
}
$att1 = isset($attachments[0]) ? $attachments[0] : '';
$att2 = isset($attachments[1]) ? $attachments[1] : '';
$att3 = isset($attachments[2]) ? $attachments[2] : '';
$wpdb->query("INSERT INTO wp_mail_daemon (notification_id,from_email,to_email,subject,text,html,attachment1,attachment2,attachment3,sent,sent_date) VALUES ($nid,'$from_email','$to_email','$subject','$alttext','$html','$att1','$att2','$att3',0,'')");
//send_email($uid,$email,$args, true);
}
}
// if the system notification has set current user than get current user otherwise loop through the users needed.
......