Hi, I guess I find it equally incomprehensible how someone with a fair bit of experience with this kind of thing fails to understand my clearly articulated instructions. 😉
Anyway, to send notification emails from wordpress@url, use the bbp_subscription_email_from filter like this (requires PHP 5.3+):
add_filter( 'bbp_subscription_email_from', function( $from ) {
return 'wordpress@' . preg_replace( '#^www\.#', '', strtolower( $_SERVER['SERVER_NAME'] ) );
}, 1, 10 );
Thread Starter
ljmac
(@ljmac)
Interesting – I actually tried exactly that function, except that I made the email simply ‘[email protected]’ instead of using all the preg replace stuff (I don’t want to use my server name – I want to use my site URL). I’ll try again.
Thread Starter
ljmac
(@ljmac)
Okay, I tried again: I keep getting [email protected]. I am running PHP 5.3. Is it necessary to do the preg replace?
Update: tried the preg replace (your exact function, but with last two numbers swapped) – same result.
-
This reply was modified 9 years, 8 months ago by
ljmac.
I’ve just checked the code. The filter expects $from to be an array containing name and email. I grant you that this isn’t clear from the instructions and I’ll make that a bit more user-friendly. The following should work:
add_filter( 'bbp_subscription_email_from', function( $from ) {
return ['', '[email protected]'];
}, 1, 10 );
Thread Starter
ljmac
(@ljmac)
Unfortunately that one completely crashed my site: “PHP Parse error: syntax error, unexpected ‘[‘”
Oh right, the array short notation was introduced with PHP 5.4. Here you go:
add_filter( 'bbp_subscription_email_from', function( $from ) {
return array( '', '[email protected]' );
}, 1, 10 );
Meh, it’s an associative array and, as you’ve noticed, the number of arguments and priority were swapped.
add_filter( 'bbp_subscription_email_from', function( $from ) {
return array( 'name' => '', 'address' => '[email protected]' );
}, 10, 1 );
I’ve just tested this on a local installation, it worked for me. I should really make the usage more clear though or accept a string in addition to the array.
Thread Starter
ljmac
(@ljmac)
I was just about to say that I’d already tried the array() option and the sender came up blank.
Anyway, the last function did indeed work for me too – thanks for your every quick response and persistence in resolving the issue. 🙂
You’re welcome. Also, I’ve just pushed an update. The $from parameter can now be a string or array, so that the more intuitive string based solution is working too. Plus, I’ve added a couple of comments to the documentation, pointing out where array parameters are expected, so that there will be less confusion on this point in the future.
Thread Starter
ljmac
(@ljmac)
Great! Very fast work. 🙂