#2701 closed defect (bug) (duplicate)
Default "do not reply" address for emails is built incorrectly
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.5.4 |
Component: | General | Keywords: | has-patch |
Cc: |
Description
Discovered this on a 2.5.4 site, but am aware of the related changes in #2618, so my line numbers will refer to the trunk.
In bbp_get_do_not_reply_address
, ltrim is used incorrectly to try to strip the http:// prefix off the start of get_home_url. ltrim works on a per character removal (on the left side of the input string) rather than a whole string match. Any h, t, p, s, colon, or forward slash characters appearing at the start of get_home_url will be removed, not just the protocol.
For example:
wp> ltrim( 'http://helpfulpaul.com', '^(http|https)://' ) string(14) "elpfulpaul.com"
This causes undeliverable or invalid emails in certain situations because (in my case) the "from" address was incorrect.
function bbp_get_do_not_reply_address() { $email = 'noreply@' . str_replace( 'www.', '', ltrim( get_home_url(), '^(http|https)://' ) ); return apply_filters( 'bbp_get_do_not_reply_address', $email ); }
I suggest the following to fix:
$email = 'noreply@' . preg_replace( '@^https?://(www\.)?@i', '', get_home_url() );
I'll patch it shortly.
Attachments (1)
Change History (5)
#3
@
10 years ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
Thanks Paul, though I'm closing as duplicate of #2618, see ticket:2618#comment:10 and attached 2618.4.diff patch.
Also of note, the regex you added should not include either of the @
character matches, get_home_url()
never includes the email @
symbol.
#4
@
10 years ago
The @
characters can be used as an alternative delimiter character for PCRE regular expressions; http://php.net/manual/en/regexp.reference.delimiters.php
Forward slashes are probably the most common, but if I used them in this patch, I would have to escape the slashes in the :/ / part of the URL, and that just makes the regex longer and harder to read. Using an alternate delimiter to avoid escaping characters is a convenience.
Patch attached.