← All changes
|
includes/admin/email_notifications/wppm_en_task_created.php
+115
-74
1.0.1
→
6.0.6
View file →
| @@ -1,75 +1,116 @@ | ||
| 1 | -<?php | |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - exit; // Exit if accessed directly | |
| 4 | -} | |
| 5 | - | |
| 6 | -global $wppmfunction, $current_user,$wpdb; | |
| 7 | -$from_name = get_option('wppm_en_from_name'); | |
| 8 | -$from_email = get_option('wppm_en_from_email'); | |
| 9 | -$ignore_emails = get_option('wppm_en_ignore_emails'); | |
| 10 | -$task_id = intval(sanitize_text_field($task_id)); | |
| 11 | -$task_data = $wppmfunction->get_task($task_id); | |
| 12 | -$project_id = $task_data['project']; | |
| 13 | -$task_users = $task_data['users']; | |
| 14 | -$task_users = explode(',',$task_users); | |
| 15 | -$flag= false; | |
| 16 | -if ( !$from_name || !$from_email ) { | |
| 17 | - return; | |
| 18 | -} | |
| 19 | -$wppm_email_notificatins = get_option('wppm_email_notification'); | |
| 20 | -foreach ($wppm_email_notificatins as $key=>$val) : | |
| 21 | - if($val['type']=='new_task'){ | |
| 22 | - $subject = $wppmfunction->replace_task_macro(stripslashes($val['subject']), $task_id); | |
| 23 | - $body = $wppmfunction->replace_task_macro(stripslashes($val['body']),$task_id); | |
| 24 | - $recipients = $val['recipients']; | |
| 25 | - $email_addresses = array(); | |
| 26 | - if(!empty($recipients)){ | |
| 27 | - foreach ($recipients as $recipient) { | |
| 28 | - if(is_numeric($recipient)){ | |
| 29 | - if($recipient == 1 && !empty($task_users)) { | |
| 30 | - foreach($task_users as $user){ | |
| 31 | - if(!empty($user)){ | |
| 32 | - $project_user_data = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = $project_id AND user_id = $user"); | |
| 33 | - $userdata = get_userdata($user); | |
| 34 | - if((!empty($project_user_data)) && $project_user_data->role_id == 1){ | |
| 35 | - $email_addresses[] = $userdata->user_email; | |
| 36 | - } | |
| 37 | - } | |
| 38 | - } | |
| 39 | - } | |
| 40 | - elseif($recipient == 2 && !empty($task_users)){ | |
| 41 | - foreach($task_users as $user){ | |
| 42 | - if(!empty($user)){ | |
| 43 | - $project_user_data = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = $project_id AND user_id = $user"); | |
| 44 | - $userdata = get_userdata($user); | |
| 45 | - if((!empty($project_user_data)) && $project_user_data->role_id == 2){ | |
| 46 | - $email_addresses[] = $userdata->user_email; | |
| 47 | - } | |
| 48 | - } | |
| 49 | - } | |
| 50 | - } | |
| 51 | - } | |
| 52 | - } | |
| 53 | - } | |
| 54 | - $email_addresses = array_unique($email_addresses); | |
| 55 | - $email_addresses = array_diff($email_addresses,$ignore_emails); | |
| 56 | - $email_addresses = array_diff($email_addresses,array($current_user->user_email)); | |
| 57 | - $email_addresses = apply_filters('wppm_en_task_users_email_addresses',$email_addresses,$val,$task_id); | |
| 58 | - $email_addresses = array_values($email_addresses); | |
| 59 | - $to = isset($email_addresses[0])? $email_addresses[0] : ''; | |
| 60 | - if($to){ | |
| 61 | - unset($email_addresses[0]); | |
| 62 | - } else { | |
| 63 | - continue; // no email address found to send. So go to next foreach iteration. | |
| 64 | - } | |
| 65 | - $bcc = implode(',',$email_addresses); | |
| 66 | - $headers = "From: {$from_name} <{$from_email}>\r\n"; | |
| 67 | - $email_addresses = explode(',',$bcc); | |
| 68 | - foreach ($email_addresses as $email_address) { | |
| 69 | - $headers .= "BCC: {$email_address}\r\n"; | |
| 70 | - } | |
| 71 | - $headers .= "Content-Type: text/html; charset=UTF-8 \r\n"; | |
| 72 | - wp_mail($to, $subject, $body, $headers); | |
| 73 | - do_action('wppm_after_submit_task_created_mail',$task_id,$val); | |
| 74 | - } | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; // Exit if accessed directly | |
| 4 | +} | |
| 5 | + | |
| 6 | +global $wppmfunction, $current_user,$wpdb; | |
| 7 | +$from_name = get_option('wppm_en_from_name'); | |
| 8 | +$from_email = get_option('wppm_en_from_email'); | |
| 9 | +$ignore_emails = get_option('wppm_en_ignore_emails'); | |
| 10 | +$task_id = absint(sanitize_text_field($task_id)); | |
| 11 | +$task_data = $wppmfunction->get_task($task_id); | |
| 12 | +$project_id = absint($task_data['project']); | |
| 13 | +$project_users = $wpdb->get_results($wpdb->prepare("SELECT user_id FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND role_id = 1",$project_id)); | |
| 14 | +$p_users = $wpdb->get_var($wpdb->prepare("SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d",$project_id)); | |
| 15 | +$p_users_array = array(); | |
| 16 | +if(isset($p_users)){ | |
| 17 | + $p_users_array = explode(',',$p_users); | |
| 18 | +} | |
| 19 | +$task_users = $task_data['users']; | |
| 20 | +$task_users = explode(',',$task_users); | |
| 21 | +$flag= false; | |
| 22 | +if ( !$from_name || !$from_email ) { | |
| 23 | + return; | |
| 24 | +} | |
| 25 | +$wppm_email_notificatins = get_option('wppm_email_notification'); | |
| 26 | +$wppm_default_email_notification_to_current_user = get_option('wppm_default_email_notification_to_current_user'); | |
| 27 | +foreach ($wppm_email_notificatins as $key=>$val) : | |
| 28 | + if($val['type']=='new_task'){ | |
| 29 | + $subject = $wppmfunction->replace_task_macro(stripslashes($val['subject']), $task_id); | |
| 30 | + $body = $wppmfunction->replace_task_macro(stripslashes($val['body']),$task_id); | |
| 31 | + $recipients = $val['recipients']; | |
| 32 | + $email_addresses = array(); | |
| 33 | + if(!empty($recipients)){ | |
| 34 | + foreach ($recipients as $recipient) { | |
| 35 | + if(is_numeric($recipient)){ | |
| 36 | + if($recipient == 1 && !empty($project_users)){ | |
| 37 | + foreach($project_users as $proj_user){ | |
| 38 | + $proj_user = (array) $proj_user; | |
| 39 | + if(in_array($proj_user['user_id'],$p_users_array)){ | |
| 40 | + $proj_userdata = get_userdata($proj_user['user_id']); | |
| 41 | + $email_addresses[] = $proj_userdata->user_email; | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 45 | + if($recipient == 1 && !empty($task_users)) { | |
| 46 | + foreach($task_users as $user){ | |
| 47 | + if(!empty($user)){ | |
| 48 | + $user = absint($user); | |
| 49 | + $project_user_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d",$project_id,$user)); | |
| 50 | + $userdata = get_userdata($user); | |
| 51 | + if((!empty($project_user_data)) && $project_user_data->role_id == 1){ | |
| 52 | + $email_addresses[] = $userdata->user_email; | |
| 53 | + } | |
| 54 | + } | |
| 55 | + } | |
| 56 | + } | |
| 57 | + elseif($recipient == 2 && !empty($task_users)){ | |
| 58 | + foreach($task_users as $user){ | |
| 59 | + if(!empty($user)){ | |
| 60 | + $user = absint($user); | |
| 61 | + $project_user_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d",$project_id,$user)); | |
| 62 | + $userdata = get_userdata($user); | |
| 63 | + if((!empty($project_user_data)) && $project_user_data->role_id == 2){ | |
| 64 | + $email_addresses[] = $userdata->user_email; | |
| 65 | + } | |
| 66 | + } | |
| 67 | + } | |
| 68 | + } | |
| 69 | + }else{ | |
| 70 | + switch ($recipient) { | |
| 71 | + case 'project_creator': | |
| 72 | + //$email_addresses = array_merge($email_addresses,$wppmfunction->get_project_creator_email($project_id)); | |
| 73 | + if ( ! empty($wppmfunction->get_project_creator_email($project_id)) ) { | |
| 74 | + $email_addresses = array_merge( | |
| 75 | + (array) $email_addresses, | |
| 76 | + (array) $wppmfunction->get_project_creator_email($project_id) | |
| 77 | + ); | |
| 78 | + } | |
| 79 | + break; | |
| 80 | + case 'task_creator': | |
| 81 | + //$email_addresses = array_merge($email_addresses,$wppmfunction->get_task_creator_email($task_id)); | |
| 82 | + if ( ! empty($wppmfunction->get_task_creator_email($task_id)) ) { | |
| 83 | + $email_addresses = array_merge( | |
| 84 | + (array) $email_addresses, | |
| 85 | + (array) $wppmfunction->get_task_creator_email($task_id) | |
| 86 | + ); | |
| 87 | + } | |
| 88 | + break; | |
| 89 | + } | |
| 90 | + } | |
| 91 | + } | |
| 92 | + } | |
| 93 | + $email_addresses = array_unique($email_addresses); | |
| 94 | + $email_addresses = array_diff($email_addresses,$ignore_emails); | |
| 95 | + if(empty($wppm_default_email_notification_to_current_user)){ | |
| 96 | + $email_addresses = array_diff($email_addresses,array($current_user->user_email)); | |
| 97 | + } | |
| 98 | + $email_addresses = apply_filters('wppm_en_task_users_email_addresses',$email_addresses,$val,$task_id); | |
| 99 | + $email_addresses = array_values($email_addresses); | |
| 100 | + $to = isset($email_addresses[0])? $email_addresses[0] : ''; | |
| 101 | + if($to){ | |
| 102 | + unset($email_addresses[0]); | |
| 103 | + } else { | |
| 104 | + continue; // no email address found to send. So go to next foreach iteration. | |
| 105 | + } | |
| 106 | + $bcc = implode(',',$email_addresses); | |
| 107 | + $headers = "From: {$from_name} <{$from_email}>\r\n"; | |
| 108 | + $email_addresses = explode(',',$bcc); | |
| 109 | + foreach ($email_addresses as $email_address) { | |
| 110 | + $headers .= "BCC: {$email_address}\r\n"; | |
| 111 | + } | |
| 112 | + $headers .= "Content-Type: text/html; charset=UTF-8 \r\n"; | |
| 113 | + wp_mail($to, $subject, $body, $headers); | |
| 114 | + do_action('wppm_after_submit_task_created_mail',$task_id,$val); | |
| 115 | + } | |
| 75 | 116 | endforeach; |