Hi Michael,
Whatever you do, don’t modify the file itself. You’ll lose your changes with the next update. See below the hooks you can use to achieve what you want. Add your custom hooks and methods either to a custom plugin (preferred) or to your functions.php file (the latter knowing that if you change themes, you lose the functionality).
For Option 1:
You can hook into the filter bbpnns_extra_headers to set the reply-to header. To get the author’s information and make it available to your extra headers hook, you can use bbpress_topic_notify_recipients and bbpress_reply_notify_recipients that will contain the Topic ID and Reply ID, respectively.
$recipients = apply_filters( 'bbpress_topic_notify_recipients', $recipients, $topic_id, $forum_id );
$recipients = apply_filters( 'bbpress_reply_notify_recipients', $recipients, $reply_id, $topic_id, $forum_id );
$headers = apply_filters( 'bbpnns_extra_headers', $headers, $recipients, $subject, $body );
For Option 2:
Hook into bbpnns_filter_email_body_in_build and process the body however you want.
$email_body = apply_filters( 'bbpnns_filter_email_body_in_build', $email_body, $type, $post_id );
Cheers,
Vinny
Closing as resolved, as I haven’t heard back.
Hello Vinny,
I try to hook in to change the Reply-To address, but I can’t get it to work. I have added this code to my functions.php. Can you please tell me what is going wrong here? Thanks for your kind help!
add_filter( 'bbpnns_extra_headers_recipient' , 'change_the_reply_to_address');
function change_the_reply_to_address($headers) {
$contactEmail = '[email protected]';
$headers = 'Reply-To: ' . $contactEmail;
return $headers;
}
Hi Erik,
Try adding the 3rd and 4th parameters to your add_filter call. Also, $headers is an array up until then. You should try to keep it that way.
Note that I haven’t tested the code below.
add_filter( 'bbpnns_extra_headers_recipient' , 'change_the_reply_to_address', 1000, 1 );
function change_the_reply_to_address($headers) {
$contactEmail = '[email protected]';
if ( is_array( $headers ) )
{
$found_reply_to = -1;
foreach ( $headers as $i => $header )
{
if ( 'reply-to' === substr( strtolower( $header ), 0, 8 ) )
{
$found_reply_to = $i;
break;
}
}
if ( -1 !== $found_reply_to )
{
unset( $headers[$found_reply_to] );
}
$headers[] = 'Reply-To: ' . $contactEmail;
}
else
{
// Not array, but really should be
$headers .= 'Reply-To: ' . $contactEmail;
}
return $headers;
}
Hello Vinny, thanks for your quick reply! I was just about to remove my above post, as my add_filter hook was already working perfectly without mentioning the 3rd and 4th arguments. Sorry and thanks again!
My pleasure. Just note that with your code you’re overwriting any additional headers altogether.