Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#16995 new defect (bug)

wp_notify_postauthor() pluggable behavior problem

Reported by: dglingren Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Mail Keywords: has-patch
Focuses: Cc:

Description (last modified by scribu)

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.

Attachments (2)

16995.diff (1.9 KB) - added by solarissmoke 3 years ago.
16995.2.diff (5.7 KB) - added by solarissmoke 3 years ago.
All nicely spaced :)

Download all attachments as: .zip

Change History (8)

comment:1 scribu3 years ago

  • Description modified (diff)
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Summary changed from wp_notify_postauthor From: problem and pluggable behavior problem to wp_notify_postauthor() pluggable behavior problem

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

Please open a new ticket for the first issue.

comment:2 scribu3 years ago

  • Version 3.1 deleted

comment:3 solarissmoke3 years ago

  • Keywords has-patch added; needs-patch removed

Patch makes behaviour consistent with wp_notify_moderator(), where the notify option is checked inside the function. This allows complete override by a custom function.

solarissmoke3 years ago

comment:4 dglingren3 years ago

Thanks for the quick action. I have applied this patch to my install and it seems to work fine.

I have opened Ticket #17001 for the "From:" issue; thanks for your guidance.

comment:5 scribu3 years ago

@solarissmoke: Coding standards:

Instead of:


it should be:

if (

Easier to prevent than to cure. ;-)

While you're at it, you can also add spacing to these lines:

$comment = get_comment($comment_id); 
wp_notify_postauthor($comment_id, $comment->comment_type);

solarissmoke3 years ago

All nicely spaced :)

comment:6 solarissmoke3 years ago

@scribu: done, and added a few spaces elsewhere while I was at it

Note: See TracTickets for help on using tickets.