Skip to main content
1 of 4
Michael
  • 123
  • 1
  • 5

Wordpress Pass Argument to add_filter

I'm attempting to override the from display name and email address using wp_mail function. I am using the hook to modify wp_mail_from with my custom function using add_filter('wp_mail_from','abcisupport_wp_mail_from'). If I hard code the value it'll return the address so it's wired up properly. If I use the argument, it returns the site network defaults. How can I pass in a value to the arguments (here: $email and $name) to my overriding functions?

function abcisupport_wp_mail_from($email) {
  return $email; //returns our default site network email address
  /* return '[email protected]'; // returns  [email protected] as the from address*/
}

function abcisupport_wp_mail_from_name($name) {
  return $name; //returns our default site network display name

}

function send_abc_mail_before_submit(){
    add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));
    add_filter('wp_mail_from','abcisupport_wp_mail_from');
    add_filter('wp_mail_from_name','abcisupport_wp_mail_from_name');

    wp_mail($to, $subject, $mailbody, $headers);

    remove_filter('wp_mail_from','abcisupport_wp_mail_from');
    remove_filter('wp_mail_from_name','abcisupport_wp_mail_from_name');
}
Michael
  • 123
  • 1
  • 5