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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 = "Content-Type: text/html; charset=UTF-8\r\n";
  16. wp_mail($destination, $this->subject, $this->body, $headers);
  17. }
  18. private function loadTemplate($template){
  19. ob_start();
  20. require("mail_templates/".$template.".html");
  21. $templateHtml=ob_get_clean();
  22. preg_match("|<subject>(.*)</subject>|",$templateHtml,$subject);
  23. $templateHtml=preg_replace("|<subject>.*</subject>|","",$templateHtml);
  24. return [
  25. "subject"=>$subject[1],
  26. "body"=>$templateHtml
  27. ];
  28. }
  29. private function inject($str,$body){
  30. foreach ($body as $key => $value) {
  31. $str=str_replace("#$key#",$value,$str);
  32. }
  33. return $str;
  34. }
  35. public function preview(){
  36. echo $this->subject;
  37. echo $this->body;
  38. }
  39. }
  40. ?>