Plugin to allow visitor contributions to WordPress posts, wiki style.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. class visitors_edits_EMAIL{
  3. var $subject;
  4. var $body;
  5. public function __construct($cpts,$template){
  6. $template=$this->loadTemplate($template);
  7. $this->subject=$this->inject($template["subject"],$cpts);
  8. $this->body=$this->inject($template["body"],$cpts);
  9. }
  10. public function send($destination){
  11. $options=get_option( "visitors_edits_options", [
  12. "admin_email"=>"",
  13. "notify_admin"=>null
  14. ]);
  15. $headers= "MIME-Version: 1.0\r\n";
  16. $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
  17. wp_mail($destination, $this->subject, $this->body,$headers);
  18. /*
  19. subject : $this->subject
  20. body : $this->body
  21. */
  22. }
  23. private function loadTemplate($template){
  24. ob_start();
  25. require("mail_templates/".$template.".html");
  26. $templateHtml=ob_get_clean();
  27. preg_match("|<subject>(.*)</subject>|",$templateHtml,$subject);
  28. $templateHtml=preg_replace("|<subject>.*</subject>|","",$templateHtml);
  29. return [
  30. "subject"=>$subject[1],
  31. "body"=>$templateHtml
  32. ];
  33. }
  34. private function inject($str,$body){
  35. foreach ($body as $key => $value) {
  36. $str=str_replace("#$key#",$value,$str);
  37. }
  38. return $str;
  39. }
  40. public function preview(){
  41. echo $this->subject;
  42. echo $this->body;
  43. }
  44. }
  45. ?>