Last active
April 16, 2021 23:44
-
-
Save strangerstudios/4699285 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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); |
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);
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?
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
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