[wp-trac] [WordPress Trac] #16995: wp_notify_postauthor() pluggable behavior problem (was: wp_notify_postauthor From: problem and pluggable behavior problem)

WordPress Trac wp-trac at lists.automattic.com
Tue Mar 29 20:39:04 UTC 2011


#16995: wp_notify_postauthor() pluggable behavior problem
--------------------------+-----------------------------
 Reporter:  dglingren     |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Mail          |     Version:  3.1
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |
--------------------------+-----------------------------
Changes (by scribu):

 * keywords:   => needs-patch
 * milestone:  Awaiting Review => Future Release


Old description:

> My application uses the "Email me whenever anyone posts a comment"
> feature in the Discussion Settings sub panel. I have found two issues
> with the default WordPress implementation of this feature.
>
> First, WordPress puts an invalid e-mail address in the "From:" header of
> all messages. In wp-includes/pluggable.php, function
> wp_notify_postauthor, line 1072 reads:
>
> {{{
> $wp_email = 'wordpress@' . preg_replace('#^www\.#', '',
> strtolower($_SERVER['SERVER_NAME']));
> }}}
>
> This means that the "From" field on all comment notification e-mails will
> contain an invalid domain name, which causes some SMTP servers to reject
> the transmission. A fix is to use the comment author's e-mail address
> when it is available:
>
> {{{
> if ( '' != $comment->comment_author_email )
>   $wp_email = $comment->comment_author_email;
> else
>   $wp_email = 'wordpress@' . preg_replace('#^www\.#', '',
> strtolower($_SERVER['SERVER_NAME']));
> }}}
>
> There are some old (2005) tickets on this issue (e.g., #2053, #1593,
> #1532), and Changeset 3214 comes close. However, the fix proposed here
> brings the "From:" address into line with the "Reply-To:" address and is
> a better fix when the comment_author_email is set.
>
> Second, in my application  a notification must be issued even when an
> author comments on their own post; this is not allowed by the default
> WordPress implementation. Lines 1015 - 1025 in function
> wp_notify_postauthor reject the author's comments and moderations.
> Since wp_notify_postauthor is a pluggable function, I can change this
> behavior by implementing my own function and replacing the default.
>
> However, there is also a redundant test of post authorship in wp-
> includes/comment.php, function wp_new_comment, around lines 1344 - 1348.
> This means that my custom wp_notify_postauthor is never called. My
> specific problem can be solved by commenting out a line of code:
>
> {{{
> // $post = &get_post($commentdata['comment_post_ID']); // Don't notify if
> it's your own comment
> }}}
>
> A real fix for this problem should move all of the user_id validation
> rules out of wp_new_comment and put them in wp_notify_postauthor where
> they can be modified as needed.

New description:

 In my application  a notification must be issued even when an author
 comments on their own post; this is not allowed by the default WordPress
 implementation. Lines 1015 - 1025 in function wp_notify_postauthor reject
 the author's comments and moderations.
 Since wp_notify_postauthor is a pluggable function, I can change this
 behavior by implementing my own function and replacing the default.

 However, there is also a redundant test of post authorship in wp-
 includes/comment.php, function wp_new_comment, around lines 1344 - 1348.
 This means that my custom wp_notify_postauthor is never called. My
 specific problem can be solved by commenting out a line of code:

 {{{
 // $post = &get_post($commentdata['comment_post_ID']); // Don't notify if
 it's your own comment
 }}}

 A real fix for this problem should move all of the user_id validation
 rules out of wp_new_comment and put them in wp_notify_postauthor where
 they can be modified as needed.

--

Comment:

 It's not a good idea to lump two issues in the same ticket.

 Please open a new ticket for the first issue.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16995#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list