Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active October 31, 2020 01:22
Show Gist options
  • Save strangerstudios/5094001 to your computer and use it in GitHub Desktop.
Save strangerstudios/5094001 to your computer and use it in GitHub Desktop.
Edit all PMPro email properties at once via pmpro_email_filter.
/*
Edit email templates.
Other fields to change:
* $email->email
* $email->from
* $email->fromname
* $email->subject
* $email->template
* $email->body
* $email->headers
*/
function my_pmpro_email_filter($email)
{
$replace_data_again = false;
if($email->template == "checkout_free")
{
//update subject
$email->subject = "Thank you for your application.";
//update body !! update this to point to a real email template file
$email->body = file_get_contents(dirname(__FILE__) . "/emails/checkout_applicant.html");
$replace_data_again = true;
}
if($replace_data_again)
{
//replace data
if(is_string($email->data))
$email->data = array("body"=>$email->data);
if(is_array($email->data))
{
foreach($email->data as $key => $value)
{
$email->body = str_replace("!!" . $key . "!!", $value, $email->body);
}
}
}
return $email;
}
add_filter("pmpro_email_filter", "my_pmpro_email_filter");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment