updated Notification to use daemon system for email notifications under system triggered.
Showing
1 changed file
with
46 additions
and
1 deletions
| ... | @@ -188,6 +188,7 @@ function remove_notice($notification_id = -1) { | ... | @@ -188,6 +188,7 @@ function remove_notice($notification_id = -1) { |
| 188 | @trigger = notification unique slug name | 188 | @trigger = notification unique slug name |
| 189 | */ | 189 | */ |
| 190 | function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array(),$send_override = false) { | 190 | function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array(),$send_override = false) { |
| 191 | global $wpdb; | ||
| 191 | $notification = get_notification_by_trigger($trigger); | 192 | $notification = get_notification_by_trigger($trigger); |
| 192 | 193 | ||
| 193 | if($notification) { | 194 | if($notification) { |
| ... | @@ -229,7 +230,51 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array(), | ... | @@ -229,7 +230,51 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array(), |
| 229 | 230 | ||
| 230 | // if is_email =========================================== | 231 | // if is_email =========================================== |
| 231 | if ($notification->is_email) { | 232 | if ($notification->is_email) { |
| 232 | send_email($uid,$email,$args, true); | 233 | |
| 234 | $user = new User\Account($uid); | ||
| 235 | |||
| 236 | $email_address_preference = get_user_meta($user->ID, 'email_address_preference', true); | ||
| 237 | if (empty($email_address_preference)) { | ||
| 238 | $to_email = $user->user_email; | ||
| 239 | } else { | ||
| 240 | |||
| 241 | $pp = strtolower($email_address_preference)."_"; | ||
| 242 | $to_email = get_user_meta($user->ID, $pp.'email', true); | ||
| 243 | |||
| 244 | if (empty($to_email)) { | ||
| 245 | $to_email = $user->user_email; | ||
| 246 | } | ||
| 247 | } | ||
| 248 | |||
| 249 | $contents = $email; | ||
| 250 | |||
| 251 | $from_email = get_bloginfo('admin_email'); | ||
| 252 | $subject = strip_tags($contents['subject']); | ||
| 253 | $html = $contents['html']; | ||
| 254 | $alttext = strip_tags($contents['text']); | ||
| 255 | |||
| 256 | foreach($args as $key => $val) { | ||
| 257 | if ( (filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { | ||
| 258 | $html = str_replace("{".$key."}","<a href='".$val."'>".$val."</a>",$html); | ||
| 259 | } else { | ||
| 260 | $html = str_replace("{".$key."}", $val, $html); | ||
| 261 | $alttext = str_replace("{".$key."}", $val, $alttext); | ||
| 262 | $subject = str_replace("{".$key."}", $val, $subject); | ||
| 263 | } | ||
| 264 | } | ||
| 265 | |||
| 266 | $attachments = array(); | ||
| 267 | if (isset($contents['attachments'])) { | ||
| 268 | $attachments = $contents['attachments']; | ||
| 269 | } | ||
| 270 | |||
| 271 | $att1 = isset($attachments[0]) ? $attachments[0] : ''; | ||
| 272 | $att2 = isset($attachments[1]) ? $attachments[1] : ''; | ||
| 273 | $att3 = isset($attachments[2]) ? $attachments[2] : ''; | ||
| 274 | |||
| 275 | $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,'')"); | ||
| 276 | |||
| 277 | //send_email($uid,$email,$args, true); | ||
| 233 | } | 278 | } |
| 234 | } | 279 | } |
| 235 | // if the system notification has set current user than get current user otherwise loop through the users needed. | 280 | // if the system notification has set current user than get current user otherwise loop through the users needed. | ... | ... |
-
Please register or sign in to post a comment