PMProEmail

The Paid Memberships Pro PMProEmail class.

Defined (1)

The class is defined in the following location(s).

/classes/class.pmproemail.php  
  1. class PMProEmail 
  2. function __construct() 
  3. $this->email = $this->from = $this->fromname = $this->subject = $this->template = $this->data = $this->body = NULL; 
  4. }  
  5.  
  6. function sendEmail($email = NULL, $from = NULL, $fromname = NULL, $subject = NULL, $template = NULL, $data = NULL) 
  7. //if values were passed 
  8. if($email) 
  9. $this->email = $email; 
  10. if($from) 
  11. $this->from = $from; 
  12. if($fromname) 
  13. $this->fromname = $fromname; 
  14. if($subject) 
  15. $this->subject = $subject; 
  16. if($template) 
  17. $this->template = $template; 
  18. if($data) 
  19. $this->data = $data; 
  20.  
  21. //default values 
  22. global $current_user; 
  23. if(!$this->email) 
  24. $this->email = $current_user->user_email; 
  25.  
  26. if(!$this->from) 
  27. $this->from = pmpro_getOption("from_email"); 
  28.  
  29. if(!$this->fromname) 
  30. $this->fromname = pmpro_getOption("from_name"); 
  31.  
  32. if(!$this->subject) 
  33. $this->subject = sprintf(__("An Email From %s", 'paid-memberships-pro' ), get_option("blogname")); 
  34.  
  35. //decode the subject line in case there are apostrophes/etc in it 
  36. $this->subject = html_entity_decode($this->subject, ENT_QUOTES, 'UTF-8'); 
  37.  
  38. if(!$this->template) 
  39. $this->template = "default"; 
  40.  
  41. $this->headers = array("Content-Type: text/html"); 
  42.  
  43. $this->attachments = NULL; 
  44.  
  45. //load the template  
  46. $locale = apply_filters("plugin_locale", get_locale(), "paid-memberships-pro"); 
  47.  
  48. if(file_exists(get_stylesheet_directory() . "/paid-memberships-pro/email/" . $locale . "/" . $this->template . ".html")) 
  49. $this->body = file_get_contents(get_stylesheet_directory() . "/paid-memberships-pro/email/" . $locale . "/" . $this->template . ".html"); //localized email folder in child theme 
  50. elseif(file_exists(get_stylesheet_directory() . "/paid-memberships-pro/email/" . $this->template . ".html")) 
  51. $this->body = file_get_contents(get_stylesheet_directory() . "/paid-memberships-pro/email/" . $this->template . ".html"); //email folder in child theme 
  52. elseif(file_exists(get_stylesheet_directory() . "/membership-email-" . $this->template . ".html")) 
  53. $this->body = file_get_contents(get_stylesheet_directory() . "/membership-email-" . $this->template . ".html"); //membership-email- file in child theme 
  54. elseif(file_exists(get_template_directory() . "/paid-memberships-pro/email/" . $locale . "/" . $this->template . ".html"))  
  55. $this->body = file_get_contents(get_template_directory() . "/paid-memberships-pro/email/" . $locale . "/" . $this->template . ".html"); //localized email folder in parent theme 
  56. elseif(file_exists(get_template_directory() . "/paid-memberships-pro/email/" . $this->template . ".html")) 
  57. $this->body = file_get_contents(get_template_directory() . "/paid-memberships-pro/email/" . $this->template . ".html"); //email folder in parent theme 
  58. elseif(file_exists(get_template_directory() . "/membership-email-" . $this->template . ".html")) 
  59. $this->body = file_get_contents(get_template_directory() . "/membership-email-" . $this->template . ".html"); //membership-email- file in parent theme  
  60. elseif(file_exists(WP_LANG_DIR . '/pmpro/email/' . $locale . "/" . $this->template . ".html")) 
  61. $this->body = file_get_contents(WP_LANG_DIR . '/pmpro/email/' . $locale . "/" . $this->template . ".html"); //localized email folder in WP language folder 
  62. elseif(file_exists(WP_LANG_DIR . '/pmpro/email/' . $this->template . ".html")) 
  63. $this->body = file_get_contents(WP_LANG_DIR . '/pmpro/email/' . $this->template . ".html"); //email folder in WP language folder 
  64. elseif(file_exists(PMPRO_DIR . "/languages/email/" . $locale . "/" . $this->template . ".html")) 
  65. $this->body = file_get_contents(PMPRO_DIR . "/languages/email/" . $locale . "/" . $this->template . ".html"); //email folder in PMPro language folder 
  66. elseif($this->getDefaultEmailTemplate($this->template)) 
  67. $this->body = $this->getDefaultEmailTemplate($this->template); 
  68. elseif(file_exists(PMPRO_DIR . "/email/" . $this->template . ".html")) 
  69. $this->body = file_get_contents(PMPRO_DIR . "/email/" . $this->template . ".html"); //default template in plugin 
  70. elseif(!empty($this->data) && !empty($this->data['body'])) 
  71. $this->body = $this->data['body']; //data passed in 
  72.  
  73. //header and footer 
  74. /** This is handled for all emails via the pmpro_send_html function in paid-memberships-pro now 
  75. if(file_exists(get_template_directory() . "/email_header.html")) 
  76. $this->body = file_get_contents(get_template_directory() . "/email_header.html") . "\n" . $this->body; 
  77. }  
  78. if(file_exists(get_template_directory() . "/email_footer.html")) 
  79. $this->body = $this->body . "\n" . file_get_contents(get_template_directory() . "/email_footer.html"); 
  80. */ 
  81.  
  82. //if data is a string, assume we mean to replace !!body!! with it 
  83. if(is_string($this->data)) 
  84. $this->data = array("body"=>$data);  
  85.  
  86. //filter for data 
  87. $this->data = apply_filters("pmpro_email_data", $this->data, $this); //filter 
  88.  
  89. //swap data into body 
  90. if(is_array($this->data)) 
  91. foreach($this->data as $key => $value) 
  92. $this->body = str_replace("!!" . $key . "!!", $value, $this->body); 
  93.  
  94. //filters 
  95. $temail = apply_filters("pmpro_email_filter", $this); //allows filtering entire email at once 
  96. $this->email = apply_filters("pmpro_email_recipient", $temail->email, $this); 
  97. $this->from = apply_filters("pmpro_email_sender", $temail->from, $this); 
  98. $this->fromname = apply_filters("pmpro_email_sender_name", $temail->fromname, $this); 
  99. $this->subject = apply_filters("pmpro_email_subject", $temail->subject, $this); 
  100. $this->template = apply_filters("pmpro_email_template", $temail->template, $this); 
  101. $this->body = apply_filters("pmpro_email_body", $temail->body, $this); 
  102. $this->headers = apply_filters("pmpro_email_headers", $temail->headers, $this); 
  103. $this->attachments = apply_filters("pmpro_email_attachments", $temail->attachments, $this); 
  104.  
  105. if(wp_mail($this->email, $this->subject, $this->body, $this->headers, $this->attachments)) 
  106. return true; 
  107. else 
  108. return false; 
  109. }  
  110.  
  111. function sendCancelEmail($user = NULL, $old_level_id = NULL) 
  112. global $wpdb, $current_user; 
  113. if(!$user) 
  114. $user = $current_user; 
  115.  
  116. if(!$user) 
  117. return false; 
  118.  
  119. $this->email = $user->user_email; 
  120. $this->subject = sprintf(__('Your membership at %s has been CANCELLED', 'paid-memberships-pro'), get_option("blogname")); 
  121.  
  122. $this->data = array("name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "siteemail" => pmpro_getOption("from_email")); 
  123.  
  124. if(!empty($old_level_id)) { 
  125. if(!is_array($old_level_id)) 
  126. $old_level_id = array($old_level_id); 
  127. $this->data['membership_id'] = $old_level_id[0]; //pass just the first as the level id 
  128. $this->data['membership_level_name'] = pmpro_implodeToEnglish($wpdb->get_col("SELECT name FROM $wpdb->pmpro_membership_levels WHERE id IN('" . implode("', '", $old_level_id) . "')")); 
  129. } else { 
  130. $this->data['membership_id'] = ''; 
  131. $this->data['membership_level_name'] = __('All Levels', 'paid-memberships-pro' ); 
  132.  
  133. $this->template = apply_filters("pmpro_email_template", "cancel", $this); 
  134. return $this->sendEmail(); 
  135.  
  136. function sendCancelAdminEmail($user = NULL, $old_level_id = NULL) 
  137. global $wpdb, $current_user; 
  138. if(!$user) 
  139. $user = $current_user; 
  140.  
  141. if(!$user) 
  142. return false; 
  143.  
  144. //check settings 
  145. $send = pmpro_getOption("email_admin_cancels"); 
  146. if(empty($send)) 
  147. return true; //didn't send, but we also don't want to indicate failure because the settings say to not send 
  148.  
  149. $this->email = get_bloginfo("admin_email"); 
  150. $this->subject = sprintf(__("Membership for %s at %s has been CANCELLED", 'paid-memberships-pro'), $user->user_login, get_option("blogname"));  
  151.  
  152. $this->data = array("user_login" => $user->user_login, "user_email" => $user->user_email, "display_name" => $user->display_name, "sitename" => get_option("blogname"), "siteemail" => pmpro_getOption("from_email"), "login_link" => wp_login_url()); 
  153.  
  154. if(!empty($old_level_id)) { 
  155. if(!is_array($old_level_id)) 
  156. $old_level_id = array($old_level_id); 
  157. $this->data['membership_id'] = $old_level_id[0]; //pass just the first as the level id 
  158. $this->data['membership_level_name'] = pmpro_implodeToEnglish($wpdb->get_col("SELECT name FROM $wpdb->pmpro_membership_levels WHERE id IN('" . implode("', '", $old_level_id) . "')")); 
  159.  
  160. //start and end date 
  161. $startdate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(startdate) as startdate FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND membership_id = '" . $old_level_id[0] . "' AND status IN('inactive', 'cancelled', 'admin_cancelled') ORDER BY id DESC"); 
  162. if(!empty($startdate)) 
  163. $this->data['startdate'] = date_i18n(get_option('date_format'), $startdate); 
  164. else 
  165. $this->data['startdate'] = ""; 
  166. $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(enddate) as enddate FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND membership_id = '" . $old_level_id[0] . "' AND status IN('inactive', 'cancelled', 'admin_cancelled') ORDER BY id DESC"); 
  167. if(!empty($enddate)) 
  168. $this->data['enddate'] = date_i18n(get_option('date_format'), $enddate); 
  169. else 
  170. $this->data['enddate'] = ""; 
  171. } else { 
  172. $this->data['membership_id'] = ''; 
  173. $this->data['membership_level_name'] = __('All Levels', 'paid-memberships-pro' ); 
  174. $this->data['startdate'] = ''; 
  175. $this->data['enddate'] = ''; 
  176.  
  177. $this->template = apply_filters("pmpro_email_template", "cancel_admin", $this); 
  178.  
  179. return $this->sendEmail(); 
  180.  
  181. function sendCheckoutEmail($user = NULL, $invoice = NULL) 
  182. global $wpdb, $current_user; 
  183. if(!$user) 
  184. $user = $current_user; 
  185.  
  186. if(!$user) 
  187. return false; 
  188.  
  189. $this->email = $user->user_email; 
  190. $this->subject = sprintf(__("Your membership confirmation for %s", 'paid-memberships-pro' ), get_option("blogname"));  
  191.  
  192. $this->data = array( 
  193. "subject" => $this->subject,  
  194. "name" => $user->display_name,  
  195. "user_login" => $user->user_login,  
  196. "sitename" => get_option("blogname"),  
  197. "siteemail" => pmpro_getOption("from_email"),  
  198. "membership_id" => $user->membership_level->id,  
  199. "membership_level_name" => $user->membership_level->name,  
  200. "membership_cost" => pmpro_getLevelCost($user->membership_level),  
  201. "login_link" => wp_login_url(pmpro_url("account")),  
  202. "display_name" => $user->display_name,  
  203. "user_email" => $user->user_email,  
  204. );  
  205.  
  206. if(!empty($invoice) && !pmpro_isLevelFree($user->membership_level)) 
  207. {  
  208. if($invoice->gateway == "paypalexpress") 
  209. $this->template = "checkout_express"; 
  210. elseif($invoice->gateway == "check") 
  211. $this->template = "checkout_check"; 
  212. $this->data["instructions"] = wpautop(pmpro_getOption("instructions")); 
  213. elseif(pmpro_isLevelTrial($user->membership_level)) 
  214. $this->template = "checkout_trial"; 
  215. else 
  216. $this->template = "checkout_paid"; 
  217.  
  218. //BUG: Didn't apply template filter before it was being used in sendEmail() 
  219. $this->template = apply_filters("pmpro_email_template", $this->template, $this); 
  220.  
  221. $this->data["invoice_id"] = $invoice->code; 
  222. $this->data["invoice_total"] = pmpro_formatPrice($invoice->total); 
  223. $this->data["invoice_date"] = date_i18n(get_option('date_format'), $invoice->timestamp); 
  224. $this->data["billing_name"] = $invoice->billing->name; 
  225. $this->data["billing_street"] = $invoice->billing->street; 
  226. $this->data["billing_city"] = $invoice->billing->city; 
  227. $this->data["billing_state"] = $invoice->billing->state; 
  228. $this->data["billing_zip"] = $invoice->billing->zip; 
  229. $this->data["billing_country"] = $invoice->billing->country; 
  230. $this->data["billing_phone"] = $invoice->billing->phone; 
  231. $this->data["cardtype"] = $invoice->cardtype; 
  232. $this->data["accountnumber"] = hideCardNumber($invoice->accountnumber); 
  233. $this->data["expirationmonth"] = $invoice->expirationmonth; 
  234. $this->data["expirationyear"] = $invoice->expirationyear; 
  235. $this->data["billing_address"] = pmpro_formatAddress($invoice->billing->name,  
  236. $invoice->billing->street,  
  237. "", //address 2 
  238. $invoice->billing->city,  
  239. $invoice->billing->state,  
  240. $invoice->billing->zip,  
  241. $invoice->billing->country,  
  242. $invoice->billing->phone); 
  243.  
  244. if($invoice->getDiscountCode()) 
  245. $this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $invoice->discount_code->code . "</p>\n"; 
  246. else 
  247. $this->data["discount_code"] = ""; 
  248. elseif(pmpro_isLevelFree($user->membership_level)) 
  249. $this->template = "checkout_free";  
  250. global $discount_code; 
  251. if(!empty($discount_code)) 
  252. $this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $discount_code . "</p>\n";  
  253. else 
  254. $this->data["discount_code"] = "";  
  255. }  
  256. else 
  257. $this->template = "checkout_freetrial"; 
  258. global $discount_code; 
  259. if(!empty($discount_code)) 
  260. $this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $discount_code . "</p>\n";  
  261. else 
  262. $this->data["discount_code"] = "";  
  263.  
  264. $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(enddate) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); 
  265. if($enddate) 
  266. $this->data["membership_expiration"] = "<p>" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "</p>\n"; 
  267. else 
  268. $this->data["membership_expiration"] = ""; 
  269.  
  270. return $this->sendEmail(); 
  271.  
  272. function sendCheckoutAdminEmail($user = NULL, $invoice = NULL) 
  273. global $wpdb, $current_user; 
  274. if(!$user) 
  275. $user = $current_user; 
  276.  
  277. if(!$user) 
  278. return false; 
  279.  
  280. //check settings 
  281. $send = pmpro_getOption("email_admin_checkout"); 
  282. if(empty($send)) 
  283. return true; //didn't send, but we also don't want to indicate failure because the settings say to not send 
  284.  
  285. $this->email = get_bloginfo("admin_email"); 
  286. $this->subject = sprintf(__("Member Checkout for %s at %s", 'paid-memberships-pro' ), $user->membership_level->name, get_option("blogname"));  
  287.  
  288. $this->data = array( 
  289. "subject" => $this->subject,  
  290. "name" => $user->display_name,  
  291. "user_login" => $user->user_login,  
  292. "sitename" => get_option("blogname"),  
  293. "siteemail" => pmpro_getOption("from_email"),  
  294. "membership_id" => $user->membership_level->id,  
  295. "membership_level_name" => $user->membership_level->name,  
  296. "membership_cost" => pmpro_getLevelCost($user->membership_level),  
  297. "login_link" => wp_login_url(pmpro_url("account")),  
  298. "display_name" => $user->display_name,  
  299. "user_email" => $user->user_email,  
  300. );  
  301.  
  302. if(!empty($invoice) && !pmpro_isLevelFree($user->membership_level)) 
  303. {  
  304. if($invoice->gateway == "paypalexpress") 
  305. $this->template = "checkout_express_admin"; 
  306. elseif($invoice->gateway == "check") 
  307. $this->template = "checkout_check_admin";  
  308. elseif(pmpro_isLevelTrial($user->membership_level)) 
  309. $this->template = "checkout_trial_admin"; 
  310. else 
  311. $this->template = "checkout_paid_admin"; 
  312.  
  313. $this->template = apply_filters( "pmpro_email_template", $this->template, $this ); 
  314.  
  315. $this->data["invoice_id"] = $invoice->code; 
  316. $this->data["invoice_total"] = pmpro_formatPrice($invoice->total); 
  317. $this->data["invoice_date"] = date_i18n(get_option('date_format'), $invoice->timestamp); 
  318. $this->data["billing_name"] = $invoice->billing->name; 
  319. $this->data["billing_street"] = $invoice->billing->street; 
  320. $this->data["billing_city"] = $invoice->billing->city; 
  321. $this->data["billing_state"] = $invoice->billing->state; 
  322. $this->data["billing_zip"] = $invoice->billing->zip; 
  323. $this->data["billing_country"] = $invoice->billing->country; 
  324. $this->data["billing_phone"] = $invoice->billing->phone; 
  325. $this->data["cardtype"] = $invoice->cardtype; 
  326. $this->data["accountnumber"] = hideCardNumber($invoice->accountnumber); 
  327. $this->data["expirationmonth"] = $invoice->expirationmonth; 
  328. $this->data["expirationyear"] = $invoice->expirationyear; 
  329. $this->data["billing_address"] = pmpro_formatAddress($invoice->billing->name,  
  330. $invoice->billing->street,  
  331. "", //address 2 
  332. $invoice->billing->city,  
  333. $invoice->billing->state,  
  334. $invoice->billing->zip,  
  335. $invoice->billing->country,  
  336. $invoice->billing->phone); 
  337.  
  338. if($invoice->getDiscountCode()) 
  339. $this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $invoice->discount_code->code . "</p>\n"; 
  340. else 
  341. $this->data["discount_code"] = ""; 
  342. elseif(pmpro_isLevelFree($user->membership_level)) 
  343. $this->template = "checkout_free_admin";  
  344. global $discount_code; 
  345. if(!empty($discount_code)) 
  346. $this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $discount_code . "</p>\n";  
  347. else 
  348. $this->data["discount_code"] = "";  
  349. }  
  350. else 
  351. $this->template = "checkout_freetrial_admin"; 
  352. $this->data["discount_code"] = ""; 
  353. }  
  354.  
  355. $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(enddate) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); 
  356. if($enddate) 
  357. $this->data["membership_expiration"] = "<p>" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "</p>\n"; 
  358. else 
  359. $this->data["membership_expiration"] = ""; 
  360.  
  361. return $this->sendEmail(); 
  362.  
  363. function sendBillingEmail($user = NULL, $invoice = NULL) 
  364. global $current_user; 
  365. if(!$user) 
  366. $user = $current_user; 
  367.  
  368. if(!$user || !$invoice) 
  369. return false; 
  370.  
  371. $this->email = $user->user_email; 
  372. $this->subject = sprintf(__("Your billing information has been updated at %s", "paid-memberships-pro"), get_option("blogname")); 
  373.  
  374. $this->data = array( 
  375. "subject" => $this->subject,  
  376. "name" => $user->display_name,  
  377. "user_login" => $user->user_login,  
  378. "sitename" => get_option("blogname"),  
  379. "siteemail" => pmpro_getOption("from_email"),  
  380. "membership_id" => $user->membership_level->id,  
  381. "membership_level_name" => $user->membership_level->name,  
  382. "display_name" => $user->display_name,  
  383. "user_email" => $user->user_email,  
  384. "billing_name" => $invoice->billing->name,  
  385. "billing_street" => $invoice->billing->street,  
  386. "billing_city" => $invoice->billing->city,  
  387. "billing_state" => $invoice->billing->state,  
  388. "billing_zip" => $invoice->billing->zip,  
  389. "billing_country" => $invoice->billing->country,  
  390. "billing_phone" => $invoice->billing->phone,  
  391. "cardtype" => $invoice->cardtype,  
  392. "accountnumber" => hideCardNumber($invoice->accountnumber),  
  393. "expirationmonth" => $invoice->expirationmonth,  
  394. "expirationyear" => $invoice->expirationyear,  
  395. "login_link" => wp_login_url(pmpro_url("account")) 
  396. ); 
  397. $this->data["billing_address"] = pmpro_formatAddress($invoice->billing->name,  
  398. $invoice->billing->street,  
  399. "", //address 2 
  400. $invoice->billing->city,  
  401. $invoice->billing->state,  
  402. $invoice->billing->zip,  
  403. $invoice->billing->country,  
  404. $invoice->billing->phone); 
  405.  
  406. $this->template = apply_filters( "pmpro_email_template", "billing", $this ); 
  407.  
  408. return $this->sendEmail(); 
  409.  
  410. function sendBillingAdminEmail($user = NULL, $invoice = NULL) 
  411. global $current_user; 
  412. if(!$user) 
  413. $user = $current_user; 
  414.  
  415. if(!$user || !$invoice) 
  416. return false; 
  417.  
  418. //check settings 
  419. $send = pmpro_getOption("email_admin_billing"); 
  420. if(empty($send)) 
  421. return true; //didn't send, but we also don't want to indicate failure because the settings say to not send 
  422.  
  423. $this->email = get_bloginfo("admin_email"); 
  424. $this->subject = sprintf(__("Billing information has been updated for %s at %s", "paid-memberships-pro"), $user->user_login, get_option("blogname")); 
  425.  
  426. $this->data = array( 
  427. "subject" => $this->subject,  
  428. "name" => $user->display_name,  
  429. "user_login" => $user->user_login,  
  430. "sitename" => get_option("blogname"),  
  431. "siteemail" => pmpro_getOption("from_email"),  
  432. "membership_id" => $user->membership_level->id,  
  433. "membership_level_name" => $user->membership_level->name,  
  434. "display_name" => $user->display_name,  
  435. "user_email" => $user->user_email,  
  436. "billing_name" => $invoice->billing->name,  
  437. "billing_street" => $invoice->billing->street,  
  438. "billing_city" => $invoice->billing->city,  
  439. "billing_state" => $invoice->billing->state,  
  440. "billing_zip" => $invoice->billing->zip,  
  441. "billing_country" => $invoice->billing->country,  
  442. "billing_phone" => $invoice->billing->phone,  
  443. "cardtype" => $invoice->cardtype,  
  444. "accountnumber" => hideCardNumber($invoice->accountnumber),  
  445. "expirationmonth" => $invoice->expirationmonth,  
  446. "expirationyear" => $invoice->expirationyear,  
  447. "login_link" => wp_login_url() 
  448. ); 
  449. $this->data["billing_address"] = pmpro_formatAddress($invoice->billing->name,  
  450. $invoice->billing->street,  
  451. "", //address 2 
  452. $invoice->billing->city,  
  453. $invoice->billing->state,  
  454. $invoice->billing->zip,  
  455. $invoice->billing->country,  
  456. $invoice->billing->phone); 
  457.  
  458. $this->template = apply_filters( "pmpro_email_template", "billing_admin", $this ); 
  459.  
  460. return $this->sendEmail(); 
  461.  
  462. function sendBillingFailureEmail($user = NULL, $invoice = NULL) 
  463. global $current_user; 
  464. if(!$user) 
  465. $user = $current_user; 
  466.  
  467. if(!$user || !$invoice) 
  468. return false; 
  469.  
  470. $this->email = $user->user_email; 
  471. $this->subject = sprintf(__("Membership Payment Failed at %s", "paid-memberships-pro"), get_option("blogname")); 
  472.  
  473. $this->data = array( 
  474. "subject" => $this->subject,  
  475. "name" => $user->display_name,  
  476. "user_login" => $user->user_login,  
  477. "sitename" => get_option("blogname"),  
  478. "siteemail" => pmpro_getOption("from_email"),  
  479. "membership_id" => $user->membership_level->id,  
  480. "membership_level_name" => $user->membership_level->name,  
  481. "display_name" => $user->display_name,  
  482. "user_email" => $user->user_email,  
  483. "billing_name" => $invoice->billing->name,  
  484. "billing_street" => $invoice->billing->street,  
  485. "billing_city" => $invoice->billing->city,  
  486. "billing_state" => $invoice->billing->state,  
  487. "billing_zip" => $invoice->billing->zip,  
  488. "billing_country" => $invoice->billing->country,  
  489. "billing_phone" => $invoice->billing->phone,  
  490. "cardtype" => $invoice->cardtype,  
  491. "accountnumber" => hideCardNumber($invoice->accountnumber),  
  492. "expirationmonth" => $invoice->expirationmonth,  
  493. "expirationyear" => $invoice->expirationyear,  
  494. "login_link" => wp_login_url(pmpro_url("billing")) 
  495. ); 
  496. $this->data["billing_address"] = pmpro_formatAddress($invoice->billing->name,  
  497. $invoice->billing->street,  
  498. "", //address 2 
  499. $invoice->billing->city,  
  500. $invoice->billing->state,  
  501. $invoice->billing->zip,  
  502. $invoice->billing->country,  
  503. $invoice->billing->phone); 
  504.  
  505. $this->template = apply_filters("pmpro_email_template", "billing_failure", $this); 
  506.  
  507. return $this->sendEmail(); 
  508. }  
  509.  
  510. function sendBillingFailureAdminEmail($email, $invoice = NULL) 
  511. {  
  512. if(!$invoice)  
  513. return false; 
  514.  
  515. $user = get_userdata($invoice->user_id); 
  516.  
  517. $this->email = $email; 
  518. $this->subject = sprintf(__("Membership Payment Failed For %s at %s", "paid-memberships-pro"), $user->display_name, get_option("blogname")); 
  519.  
  520. $this->data = array( 
  521. "subject" => $this->subject,  
  522. "name" => "Admin",  
  523. "user_login" => $user->user_login,  
  524. "sitename" => get_option("blogname"),  
  525. "siteemail" => pmpro_getOption("from_email"),  
  526. "membership_id" => $user->membership_level->id,  
  527. "membership_level_name" => $user->membership_level->name,  
  528. "display_name" => $user->display_name,  
  529. "user_email" => $user->user_email,  
  530. "billing_name" => $invoice->billing->name,  
  531. "billing_street" => $invoice->billing->street,  
  532. "billing_city" => $invoice->billing->city,  
  533. "billing_state" => $invoice->billing->state,  
  534. "billing_zip" => $invoice->billing->zip,  
  535. "billing_country" => $invoice->billing->country,  
  536. "billing_phone" => $invoice->billing->phone,  
  537. "cardtype" => $invoice->cardtype,  
  538. "accountnumber" => hideCardNumber($invoice->accountnumber),  
  539. "expirationmonth" => $invoice->expirationmonth,  
  540. "expirationyear" => $invoice->expirationyear,  
  541. "login_link" => wp_login_url(pmpro_url("billing")) 
  542. ); 
  543. $this->data["billing_address"] = pmpro_formatAddress($invoice->billing->name,  
  544. $invoice->billing->street,  
  545. "", //address 2 
  546. $invoice->billing->city,  
  547. $invoice->billing->state,  
  548. $invoice->billing->zip,  
  549. $invoice->billing->country,  
  550. $invoice->billing->phone); 
  551. $this->template = apply_filters("pmpro_email_template", "billing_failure_admin", $this); 
  552.  
  553. return $this->sendEmail(); 
  554.  
  555. function sendCreditCardExpiringEmail($user = NULL, $invoice = NULL) 
  556. global $current_user; 
  557. if(!$user) 
  558. $user = $current_user; 
  559.  
  560. if(!$user || !$invoice) 
  561. return false; 
  562.  
  563. $this->email = $user->user_email; 
  564. $this->subject = sprintf(__("Credit Card on File Expiring Soon at %s", "paid-memberships-pro"), get_option("blogname")); 
  565.  
  566. $this->data = array( 
  567. "subject" => $this->subject,  
  568. "name" => $user->display_name,  
  569. "user_login" => $user->user_login,  
  570. "sitename" => get_option("blogname"),  
  571. "siteemail" => pmpro_getOption("from_email"),  
  572. "membership_id" => $user->membership_level->id,  
  573. "membership_level_name" => $user->membership_level->name,  
  574. "display_name" => $user->display_name,  
  575. "user_email" => $user->user_email,  
  576. "billing_name" => $invoice->billing->name,  
  577. "billing_street" => $invoice->billing->street,  
  578. "billing_city" => $invoice->billing->city,  
  579. "billing_state" => $invoice->billing->state,  
  580. "billing_zip" => $invoice->billing->zip,  
  581. "billing_country" => $invoice->billing->country,  
  582. "billing_phone" => $invoice->billing->phone,  
  583. "cardtype" => $invoice->cardtype,  
  584. "accountnumber" => hideCardNumber($invoice->accountnumber),  
  585. "expirationmonth" => $invoice->expirationmonth,  
  586. "expirationyear" => $invoice->expirationyear,  
  587. "login_link" => wp_login_url(pmpro_url("billing")) 
  588. ); 
  589. $this->data["billing_address"] = pmpro_formatAddress($invoice->billing->name,  
  590. $invoice->billing->street,  
  591. "", //address 2 
  592. $invoice->billing->city,  
  593. $invoice->billing->state,  
  594. $invoice->billing->zip,  
  595. $invoice->billing->country,  
  596. $invoice->billing->phone); 
  597.  
  598. $this->template = apply_filters("pmpro_email_template", "credit_card_expiring", $this); 
  599.  
  600. return $this->sendEmail(); 
  601.  
  602. function sendInvoiceEmail($user = NULL, $invoice = NULL) 
  603. global $wpdb, $current_user; 
  604. if(!$user) 
  605. $user = $current_user; 
  606.  
  607. if(!$user || !$invoice) 
  608. return false; 
  609.  
  610. $user->membership_level = pmpro_getMembershipLevelForUser($user->ID); 
  611.  
  612. $this->email = $user->user_email; 
  613. $this->subject = sprintf(__("INVOICE for %s membership", "paid-memberships-pro"), get_option("blogname")); 
  614.  
  615. $this->data = array( 
  616. "subject" => $this->subject,  
  617. "name" => $user->display_name,  
  618. "user_login" => $user->user_login,  
  619. "sitename" => get_option("blogname"),  
  620. "siteemail" => pmpro_getOption("from_email"),  
  621. "membership_id" => $user->membership_level->id,  
  622. "membership_level_name" => $user->membership_level->name,  
  623. "display_name" => $user->display_name,  
  624. "user_email" => $user->user_email,  
  625. "invoice_id" => $invoice->code,  
  626. "invoice_total" => pmpro_formatPrice($invoice->total),  
  627. "invoice_date" => date_i18n(get_option('date_format'), $invoice->timestamp),  
  628. "billing_name" => $invoice->billing->name,  
  629. "billing_street" => $invoice->billing->street,  
  630. "billing_city" => $invoice->billing->city,  
  631. "billing_state" => $invoice->billing->state,  
  632. "billing_zip" => $invoice->billing->zip,  
  633. "billing_country" => $invoice->billing->country,  
  634. "billing_phone" => $invoice->billing->phone,  
  635. "cardtype" => $invoice->cardtype,  
  636. "accountnumber" => hideCardNumber($invoice->accountnumber),  
  637. "expirationmonth" => $invoice->expirationmonth,  
  638. "expirationyear" => $invoice->expirationyear,  
  639. "login_link" => wp_login_url(pmpro_url("account")),  
  640. "invoice_link" => wp_login_url(pmpro_url("invoice", "?invoice=" . $invoice->code) 
  641. )); 
  642. $this->data["billing_address"] = pmpro_formatAddress($invoice->billing->name,  
  643. $invoice->billing->street,  
  644. "", //address 2 
  645. $invoice->billing->city,  
  646. $invoice->billing->state,  
  647. $invoice->billing->zip,  
  648. $invoice->billing->country,  
  649. $invoice->billing->phone); 
  650.  
  651. if($invoice->getDiscountCode()) { 
  652. if(!empty($invoice->discount_code->code)) 
  653. $this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $invoice->discount_code->code . "</p>\n"; 
  654. else 
  655. $this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $invoice->discount_code . "</p>\n"; 
  656. } else { 
  657. $this->data["discount_code"] = ""; 
  658.  
  659. $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(enddate) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); 
  660. if($enddate) 
  661. $this->data["membership_expiration"] = "<p>" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "</p>\n"; 
  662. else 
  663. $this->data["membership_expiration"] = ""; 
  664.  
  665.  
  666. $this->template = apply_filters("pmpro_email_template", "invoice", $this); 
  667.  
  668. return $this->sendEmail(); 
  669.  
  670. function sendTrialEndingEmail($user = NULL) 
  671. global $current_user, $wpdb; 
  672. if(!$user) 
  673. $user = $current_user; 
  674.  
  675. if(!$user) 
  676. return false; 
  677.  
  678. //make sure we have the current membership level data 
  679. /**$user->membership_level = $wpdb->get_row("SELECT l.id AS ID, l.name AS name, UNIX_TIMESTAMP(mu.startdate) as startdate, mu.billing_amount, mu.cycle_number, mu.cycle_period, mu.trial_amount, mu.trial_limit 
  680. FROM {$wpdb->pmpro_membership_levels} AS l 
  681. JOIN {$wpdb->pmpro_memberships_users} AS mu ON (l.id = mu.membership_id) 
  682. WHERE mu.user_id = " . $user->ID . " 
  683. LIMIT 1");*/ 
  684. $user->membership_level = pmpro_getMembershipLevelForUser($user->ID); 
  685.  
  686. $this->email = $user->user_email; 
  687. $this->subject = sprintf(__("Your trial at %s is ending soon", "paid-memberships-pro"), get_option("blogname")); 
  688.  
  689. $this->data = array( 
  690. "subject" => $this->subject,  
  691. "name" => $user->display_name,  
  692. "user_login" => $user->user_login,  
  693. "sitename" => get_option("blogname"),  
  694. "membership_id" => $user->membership_level->id,  
  695. "membership_level_name" => $user->membership_level->name,  
  696. "siteemail" => pmpro_getOption("from_email"),  
  697. "login_link" => wp_login_url(),  
  698. "display_name" => $user->display_name,  
  699. "user_email" => $user->user_email,  
  700. "billing_amount" => pmpro_formatPrice($user->membership_level->billing_amount),  
  701. "cycle_number" => $user->membership_level->cycle_number,  
  702. "cycle_period" => $user->membership_level->cycle_period,  
  703. "trial_amount" => pmpro_formatPrice($user->membership_level->trial_amount),  
  704. "trial_limit" => $user->membership_level->trial_limit,  
  705. "trial_end" => date_i18n(get_option('date_format'), strtotime(date_i18n("m/d/Y", $user->membership_level->startdate) . " + " . $user->membership_level->trial_limit . " " . $user->membership_level->cycle_period), current_time("timestamp")) 
  706. ); 
  707.  
  708. $this->template = apply_filters("pmpro_email_template", "trial_ending", $this); 
  709.  
  710. return $this->sendEmail(); 
  711.  
  712. function sendMembershipExpiredEmail($user = NULL) 
  713. global $current_user, $wpdb; 
  714. if(!$user) 
  715. $user = $current_user; 
  716.  
  717. if(!$user) 
  718. return false;  
  719.  
  720. $this->email = $user->user_email; 
  721. $this->subject = sprintf(__("Your membership at %s has ended", "paid-memberships-pro"), get_option("blogname"));  
  722.  
  723. $this->data = array("subject" => $this->subject, "name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "siteemail" => pmpro_getOption("from_email"), "login_link" => wp_login_url(), "display_name" => $user->display_name, "user_email" => $user->user_email, "levels_link" => pmpro_url("levels")); 
  724.  
  725. $this->template = apply_filters("pmpro_email_template", "membership_expired", $this); 
  726.  
  727. return $this->sendEmail(); 
  728.  
  729. function sendMembershipExpiringEmail($user = NULL) 
  730. global $current_user, $wpdb; 
  731. if(!$user) 
  732. $user = $current_user; 
  733.  
  734. if(!$user) 
  735. return false; 
  736.  
  737. //make sure we have the current membership level data 
  738. /**$user->membership_level = $wpdb->get_row("SELECT l.id AS ID, l.name AS name, UNIX_TIMESTAMP(mu.enddate) as enddate 
  739. FROM {$wpdb->pmpro_membership_levels} AS l 
  740. JOIN {$wpdb->pmpro_memberships_users} AS mu ON (l.id = mu.membership_id) 
  741. WHERE mu.user_id = " . $user->ID . " 
  742. LIMIT 1");*/ 
  743. $user->membership_level = pmpro_getMembershipLevelForUser($user->ID); 
  744.  
  745. $this->email = $user->user_email; 
  746. $this->subject = sprintf(__("Your membership at %s will end soon", "paid-memberships-pro"), get_option("blogname")); 
  747.  
  748. $this->data = array("subject" => $this->subject, "name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "membership_id" => $user->membership_level->id, "membership_level_name" => $user->membership_level->name, "siteemail" => pmpro_getOption("from_email"), "login_link" => wp_login_url(), "enddate" => date_i18n(get_option('date_format'), $user->membership_level->enddate), "display_name" => $user->display_name, "user_email" => $user->user_email); 
  749.  
  750. $this->template = apply_filters("pmpro_email_template", "membership_expiring", $this); 
  751.  
  752. return $this->sendEmail(); 
  753.  
  754. function sendAdminChangeEmail($user = NULL) 
  755. global $current_user, $wpdb; 
  756. if(!$user) 
  757. $user = $current_user; 
  758.  
  759. if(!$user) 
  760. return false; 
  761.  
  762. //make sure we have the current membership level data 
  763. $user->membership_level = pmpro_getMembershipLevelForUser($user->ID, true); 
  764.  
  765. $this->email = $user->user_email; 
  766. $this->subject = sprintf(__("Your membership at %s has been changed", "paid-memberships-pro"), get_option("blogname")); 
  767.  
  768. $this->data = array("subject" => $this->subject, "name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "membership_id" => $user->membership_level->id, "membership_level_name" => $user->membership_level->name, "siteemail" => pmpro_getOption("from_email"), "login_link" => wp_login_url()); 
  769.  
  770. if($user->membership_level->ID) 
  771. $this->data["membership_change"] = sprintf(__("The new level is %s", 'paid-memberships-pro' ), $user->membership_level->name); 
  772. else 
  773. $this->data["membership_change"] = __("Your membership has been cancelled", "paid-memberships-pro"); 
  774.  
  775. if(!empty($user->membership_level->enddate)) 
  776. $this->data["membership_change"] .= ". " . sprintf(__("This membership will expire on %s", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $user->membership_level->enddate)); 
  777. elseif(!empty($this->expiration_changed)) 
  778. $this->data["membership_change"] .= ". " . __("This membership does not expire", 'paid-memberships-pro' ); 
  779.  
  780. $this->template = apply_filters("pmpro_email_template", "admin_change", $this); 
  781.  
  782. return $this->sendEmail(); 
  783.  
  784. function sendAdminChangeAdminEmail($user = NULL) 
  785. global $current_user, $wpdb; 
  786. if(!$user) 
  787. $user = $current_user; 
  788.  
  789. if(!$user) 
  790. return false; 
  791.  
  792. //check settings 
  793. $send = pmpro_getOption("email_admin_changes"); 
  794. if(empty($send)) 
  795. return true; //didn't send, but we also don't want to indicate failure because the settings say to not send 
  796.  
  797. //make sure we have the current membership level data 
  798. $user->membership_level = pmpro_getMembershipLevelForUser($user->ID, true); 
  799.  
  800. $this->email = get_bloginfo("admin_email"); 
  801. $this->subject = sprintf(__("Membership for %s at %s has been changed", "paid-memberships-pro"), $user->user_login, get_option("blogname")); 
  802.  
  803. $this->data = array("subject" => $this->subject, "name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "membership_level_name" => $user->membership_level->name, "siteemail" => get_bloginfo("admin_email"), "login_link" => wp_login_url()); 
  804. if($user->membership_level->ID) 
  805. $this->data["membership_change"] = sprintf(__("The new level is %s", 'paid-memberships-pro' ), $user->membership_level->name); 
  806. else 
  807. $this->data["membership_change"] = __("Membership has been cancelled", 'paid-memberships-pro' ); 
  808.  
  809. if(!empty($user->membership_level->enddate)) 
  810. $this->data["membership_change"] .= ". " . sprintf(__("This membership will expire on %s", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $user->membership_level->enddate)); 
  811. elseif(!empty($this->expiration_changed)) 
  812. $this->data["membership_change"] .= ". " . __("This membership does not expire", 'paid-memberships-pro' ); 
  813.  
  814. $this->template = apply_filters("pmpro_email_template", "admin_change_admin", $this); 
  815.  
  816. return $this->sendEmail(); 
  817.  
  818. /** 
  819. * Send billable invoice email. 
  820. * @since 1.8.6 
  821. * @param WP_User $user 
  822. * @param MemberOrder $order 
  823. * @return bool Whether the email was sent successfully. 
  824. */ 
  825. function sendBillableInvoiceEmail($user = NULL, $order = NULL) 
  826. global $current_user; 
  827.  
  828. if(!$user) 
  829. $user = $current_user; 
  830.  
  831. if(!$user || !$order) 
  832. return false; 
  833.  
  834. $level = pmpro_getLevel($order->membership_id); 
  835.  
  836. $this->email = $user->user_email; 
  837. $this->subject = __('Invoice for Order #: ', 'paid-memberships-pro') . $order->code; 
  838.  
  839. // Load invoice template 
  840. if ( file_exists( get_stylesheet_directory() . '/paid-memberships-pro/pages/orders-email.php' ) ) { 
  841. $template = get_stylesheet_directory() . '/paid-memberships-pro/pages/orders-email.php'; 
  842. } elseif ( file_exists( get_template_directory() . '/paid-memberships-pro/pages/orders-email.php' ) ) { 
  843. $template = get_template_directory() . '/paid-memberships-pro/pages/orders-email.php'; 
  844. } else { 
  845. $template = PMPRO_DIR . '/adminpages/templates/orders-email.php'; 
  846.  
  847. ob_start(); 
  848. require_once( $template ); 
  849.  
  850. $invoice = ob_get_contents(); 
  851. ob_end_clean(); 
  852.  
  853. $this->data = array( 
  854. 'order_code' => $order->code,  
  855. 'login_link' => wp_login_url(pmpro_url("account")),  
  856. 'invoice_link' => wp_login_url(pmpro_url("invoice", "?invoice=" . $order->code)),  
  857. 'invoice' => $invoice 
  858. ); 
  859.  
  860. $this->template = apply_filters("pmpro_email_template", "billable_invoice", $this); 
  861.  
  862. return $this->sendEmail(); 
  863.  
  864. /** 
  865. * Load the text for each default email template. 
  866. * This overrides the old /email/**.html templates. 
  867. */ 
  868. function getDefaultEmailTemplate( $template = null ) { 
  869. if( empty( $template ) && !empty( $this->template ) ) 
  870. $template = $this->template; 
  871.  
  872. if( empty( $template ) ) 
  873. return false; 
  874.  
  875. $r = ''; 
  876.  
  877. switch($template) { 
  878. case "admin_change": 
  879. $r = __( "<p>An administrator at !!sitename!! has changed your membership level.</p> 
  880.  
  881. <p>!!membership_change!!.</p> 
  882.  
  883. <p>If you did not request this membership change and would like more information please contact us at !!siteemail!!</p> 
  884.  
  885. <p>Log in to your membership account here: !!login_link!!</p>", 'paid-memberships-pro' ); 
  886. break; 
  887. //repeat above for each template 
  888.  
  889. return $r;