1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Redefine user notification function

if ( !function_exists('wp_new_user_notification') ) {

  function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {

  $user = new WP_User($user_id);  //Take the $user_id and use the WP_User function to access all information about the newly registered user
  
  send_welcome_emails($user);  //Call the email sending function and pass it all the user data
  }
}


function send_welcome_emails($user){
  
  $user_login = stripslashes($user->user_login);
  $user_email = stripslashes($user->user_email);
  $user_password = stripslashes($user->user_pass);
  $user_id = stripslashes($user->ID);

  $role = get_user_role($user_login);
  
  $headers = "From: My Doctors' Chemist <[email protected]>";
  $sbreak = "<br />";
  $break = "<br/ ><br />";
  $home_url = get_home_url();
  
  if($role == "patient"){
    $patient_first_name = get_user_meta($user_id, "wpcf-patient-first-name", true);
    $patient_second_name = get_user_meta($user_id, "wpcf-patient-second-name", true);
    
    $to = $user_email;
    $subject = "Welcome to My Doctors' Chemist";
    
    $intro = "Dear " . $patient_first_name . "," . $sbreak . "Thank you for registering with My Doctors' Chemist!  You will shortly be able to order your medications online at your convienience.  Please find enclosed in this email a copy of your username and password which you can now use to login to our website and begin adding your medications from a prescription.";
    $patient_username = "Your username will be: " . $user_login;
    $patient_password = "Your password will be: " . $user_password;
    $login = 'Login at <a href=". $home_url . "/user-home';
    $end = 'We hope you find our services to be first class and we would like to take this opertunity to welcome you and if you require any assistance whatsoever then please contact us in the office via email on <a href="mailto:[email protected]">[email protected]</a>' . $break . "Regards," . $sbreak . "The My Doctors' Chemist Team";
    
    $message = $intro . $break. $patient_username . $sbreak . $patient_password . $break . $login . $end;
    
    $toc = "[email protected]";
    $subjectc = "A New Patient has Registered Online";
    $introc = "A new patient, " . $patient_first_name . " " . $patient_second_name . " has registered on the website.";
    $url = $home_url . "/patient/" . $user_login;    
    $messagec = $introc . $break. $url;
    
  }elseif($role == "care_home_admin"){
    $home_post_id = get_post_id_from_title($user_login);
    
    $home_name = get_post_meta($home_post_id, "wpcf-home-name", true);
    $home_type = get_post_meta($home_post_id, "wpcf-home-type", true);
  
    var_dump($home_post_id);
    var_dump($home_name);
    var_dump($home_type);
  
    if($home_type == 1){
      $type_name = "Care";
      $email = "[email protected]";
    }elseif($home_type == 2){
      $type_name = "Nursing";
      $email = "[email protected]";
    }
    
    var_dump($type_name);
    var_dump($email);
    
    $to = $user_email;
    $subject = "Welcome to My Doctors' Chemist";
    
    $intro = "Dear <b>" . $home_name . "</b>," . $break . "Thank you for choosing with My Doctors' Chemist!  You will shortly be begin setting your home up online at your convienience.  Please find enclosed in this email a copy of your username and password which you can now use to login to our website and begin adding your residents and their medications.";
    $patient_username = "Your username will be: <b>" . $user_login . "</b>";
    $patient_password = "Your password will be: <b>" . $user_password . "</b>";
    $login = 'Login at <a href=". $home_url . "/user-home';
    $end = 'We hope you find our services to be first class and we would like to take this opertunity to welcome you and if you require any assistance whatsoever then please contact us in the office via email on <a href="mailto:[email protected]">[email protected]</a>' . $break . 'alternatively for an urgent matter call us on 0800 0832246' . $break . "Regards," . $sbreak . "The My Doctors' Chemist Team";
    
    $url = $home_url . "/home/" . $user_login;
    $message = $intro . $break. $patient_username . $sbreak . $patient_password . $break . $end;
    
    $toc = $email;
    $subjectc = "A New " . $type_name . " Home has been Registered Online";
    $introc = "A new " . $type_name . " Home has been registered on the website.";    
    $messagec = $introc . $break. $url;
    
  }
  /*die();*/
  send_emails($to, $subject, $message, $headers);
  send_emails($toc, $subjectc, $messagec, $headers);
  
}