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.
 
 
 
 

42 lines
1.1 KiB

<?php
class visitors_edits_EMAIL{
var $subject;
var $body;
public function __construct($cpts,$template){
$template=$this->loadTemplate($template);
$this->subject=$this->inject($template["subject"],$cpts);
$this->body=$this->inject($template["body"],$cpts);
}
public function send($destination){
$options=get_option( "visitors_edits_options", [
"admin_email"=>"",
"notify_admin"=>null
]);
$headers = "Content-Type: text/html; charset=UTF-8\r\n";
wp_mail($destination, $this->subject, $this->body, $headers);
}
private function loadTemplate($template){
ob_start();
require("mail_templates/".$template.".html");
$templateHtml=ob_get_clean();
preg_match("|<subject>(.*)</subject>|",$templateHtml,$subject);
$templateHtml=preg_replace("|<subject>.*</subject>|","",$templateHtml);
return [
"subject"=>$subject[1],
"body"=>$templateHtml
];
}
private function inject($str,$body){
foreach ($body as $key => $value) {
$str=str_replace("#$key#",$value,$str);
}
return $str;
}
public function preview(){
echo $this->subject;
echo $this->body;
}
}
?>