[wp-trac] [WordPress Trac] #25699: When filtering comment notification email recipients, notifications are not sent for author comments
WordPress Trac
noreply at wordpress.org
Sun Oct 27 08:02:23 UTC 2013
#25699: When filtering comment notification email recipients, notifications are not
sent for author comments
--------------------------+------------------
Reporter: chipbennett | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 3.8
Component: Comments | Version: 3.7
Severity: minor | Resolution:
Keywords: |
--------------------------+------------------
Comment (by DaveAl):
Replying to [ticket:25699 chipbennett]:
> Reference support thread:
> http://wordpress.org/support/topic/no-notifications-when-post-author-
comments?replies=9
>
> Core filters `'comment_notification_recipients'` for
`wp_notify_postauthor()` and `'comment_moderation_recipients'` for
`wp_notify_moderator()` were added in WordPress 3.7. When
`'comment_notification_recipients'` is filtered to add additional
recipients, no email notification is sent for post-author comments.
>
> This issue occurs because of this conditional check in the
`wp_new_comment()` function in `wp-includes/comment.php`:
>
> {{{
> if ( get_option('comments_notify') && $commentdata['comment_approved']
&& ( ! isset( $commentdata['user_id'] ) || $post->post_author !=
$commentdata['user_id'] ) )
> wp_notify_postauthor($comment_ID, isset(
$commentdata['comment_type'] ) ? $commentdata['comment_type'] : '' );
> }}}
>
> Specifically:
> {{{
> $post->post_author != $commentdata['user_id']
> }}}
>
> Obviously, this conditional is in place for good reason (post authors
don't need to receive notification for their own comments); but it
interferes with email notification for multiple recipients.
>
> I'd be happy to patch, but I'm not sure of the most elegant solution.
There appear to be two problems to solve - both in similar fashion - and a
question.
1. In wp_new_comment(), a check for multiple recipients needs to be added
to the if condition, something along the lines of:
{{{
$recipients = count( apply_filters( 'comment_notification_recipients',
$recipients, $comment_id ) );
...
...
if ( get_option('comments_notify') && $commentdata['comment_approved'] &&
( ! isset( $commentdata['user_id'] ) || $post->post_author !=
$commentdata['user_id'] || $recipients > 1 ) )
wp_notify_postauthor($comment_ID, isset(
$commentdata['comment_type'] ) ? $commentdata['comment_type'] : '' );
}}}
2. A similar check would need to be added to wp_notify_postauthor in
pluggable.php to prevent it from returning in the case of multiple
recipients:
{{{
$recipients = count( apply_filters( 'comment_notification_recipients',
$recipients, $comment_id ) );
...
...
// The comment was left by the author
if ( $comment->user_id == $post->post_author && $recipients <= 1 )
return false;
}}}
Finally, the question: If there are multiple recipients and the comment is
from the post author, should the post author be removed from the list of
recipients? This could actually be done in the email loop by simply
skipping that one email address:
{{{
foreach ( $emails as $email ) {
if ( $email != $author->user_email || $comment->user_id !=
$post->post_author ) {
@wp_mail( $email, $subject, $notify_message, $message_headers
);
}
}
}}}
Personally, I would include the author in the case of multiple recipients,
if for no other reason than to alert the author that notifications were
sent, not to mention it would be a little less code to mess with.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25699#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list