Skip to content

Instantly share code, notes, and snippets.

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/4699285 to your computer and use it in GitHub Desktop.
Save strangerstudios/4699285 to your computer and use it in GitHub Desktop.
/*
Only change the from email/name on PMPro emails.
This code is useful if Paid Memberships Pro is updating the from name and email on non-PMPro emails and you don't want it to.
Add this code to your active theme's functions.php or a custom plugin.
*/
function my_pmpro_email_headers_init()
{
//first remove the default actions
remove_filter('wp_mail_from_name', 'pmpro_wp_mail_from_name');
remove_filter('wp_mail_from', 'pmpro_wp_mail_from');
//filters to update from name and email in PMProEmail class
add_filter('pmpro_email_sender_name', 'pmpro_wp_mail_from_name');
add_filter('pmpro_email_sender', 'pmpro_wp_mail_from');
}
add_action("init", "my_pmpro_email_headers_init");
//actually use those values when sending the email
function my_pmpro_email_headers($headers, $email)
{
$pmpro_from_name = pmpro_getOption("from_name");
$pmpro_from_email = pmpro_getOption("from_email");
if(!empty($pmpro_from_name) && !empty($pmpro_from_email))
$headers[]="From: " . $pmpro_from_name . " <" . $pmpro_from_email . ">";
return $headers;
}
add_filter('pmpro_email_headers', 'my_pmpro_email_headers', 10, 2);
@rwilki
Copy link

rwilki commented Feb 25, 2014

Works great except for error upon membership cancellation...
Warning: Missing argument 2 for my_pmpro_email_headers() in /home/xxxxxxx/xxxxxxx/wp-content/themes/themename/functions.php on line 748

@strangerstudios
Copy link
Author

Thanks for the heads up. I fixed the gist by adding , 10, 2 to the add_filter line:

add_filter('pmpro_email_headers', 'my_pmpro_email_headers', 10, 2);

@Carolacat
Copy link

Hi thanks for this info. I have been having the same problem. Silly question maybe, but does this code go into the functions.php file? Any particular place?

@laurenhagan0306
Copy link

This recipe is included in the blog post on "Only change the from email and name on PMPro emails." at Paid Memberships Pro here: https://www.paidmembershipspro.com/only-change-the-from-email-and-name-on-pmpro-emails/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment