Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active April 7, 2018 21:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save strangerstudios/5788300 to your computer and use it in GitHub Desktop.
Save strangerstudios/5788300 to your computer and use it in GitHub Desktop.
Change admin_change email tempalte sent by Paid Memberships Pro to members when they move from one level to another. Useful for "approval" workflows on sign up.
/*
Change admin_change email sent to members when they move from "Applicant" level to "Approved" level.
You should have two levels, "Applicant" level ID 1 and "Approved" level ID 2.
If the names or IDs of your levels are different, you will have to change the code below.
You also need a file "applicant_approved.html" in the ../themes/yourtheme/paid-memberships-pro/email/ directory.
*/
function my_pmpro_email_filter($email)
{
if($email->template == "admin_change" && $email->data['membership_level_name'] == "Approved")
{
//check if this user's last level was 1
global $wpdb;
$user = get_user_by("login", $email->data['user_login']);
$last_level_id = $wpdb->get_var("SELECT membership_id FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status != 'active' ORDER BY id DESC LIMIT 1");
if($last_level_id != 1)
return $email; //wasn't an applicant before this change.
//update subject
$email->subject = "Your application to " . get_option('blogname') . " has been approved.";
//update body
$email->body = file_get_contents(get_stylesheet_directory() . "/paid-memberships-pro/email/applicant_approved.html");
//replace data
if(is_string($email->data))
$email->data = array("body"=>$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