WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 8 months ago

Last modified 8 months ago

#20353 closed enhancement (fixed)

Add filter for email recipients in wp_notify_moderator()

Reported by: lexhair Owned by: nacin
Milestone: 3.7 Priority: normal
Severity: minor Version: 3.3.1
Component: Comments Keywords: has-patch needs-testing
Focuses: Cc:

Description

As administrator, I would like more control over email notifications when comments are marked for moderation without having to overwrite the pluggable function wp_notify_moderator.

The function wp_notify_moderator sends emails to post authors (when they have sufficient roles) and the admin by hard coding the $email_to array. I'd like to see the $email_to array sent to a filter with $comment before wp_mail() is called. That would allow me to write a theme function to manipulate the $email_to array to add or delete recipients.

My workaround was to write a site specific plugin that overwrote wp_notify_moderator() to manipulate the $email_to array.

Attachments (1)

pluggable.php.wp_notify_moderator.diff (676 bytes) - added by chipbennett 16 months ago.
Applies 'comment_moderation_email_to' filters to $email_to array

Download all attachments as: .zip

Change History (9)

comment:2 lexhair2 years ago

#8833 is a big task.

Many of the pluggable functions, including wp_notify_moderator() have filter hooks already available. This would be a simple line of code which I'd be happy to prepare a patch for that would apply a filter.

I could have made this work by hooking into wp_mail() but phpmailer makes the To: address property protected which was giving me fits to manipulate it.

comment:3 juliobox22 months ago

I agree lexhair, this filter is easy to implement and in fact, i'm wondering why the foreach loops on a single item oO
It seems a filter is missing here!
How can i propose a patch?

chipbennett16 months ago

Applies 'comment_moderation_email_to' filters to $email_to array

comment:4 chipbennett16 months ago

  • Component changed from General to Comments
  • Keywords has-patch needs-testing added

Patch passes $email_to array through apply_filters(), for the 'comment_moderation_email_to' filter.

Related: #22922

comment:5 nacin8 months ago

  • Milestone changed from Awaiting Review to 3.7

comment:6 chipbennett8 months ago

Thanks, Nacin! The related ticket #22922 is equally low-hanging fruit, and the two combined scratch a particular itch of mine.

comment:7 nacin8 months ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 25104:

Add filters to the recipients of emails sent by wp_notify_postauthor() and wp_notify_moderator().

The new filters are called comment_notification_recipients and comment_moderation_recipients.

Add the context of $comment_id to the comment_moderation_headers filter, to match the comment_notification_headers filter.

props chipbennett.
fixes #22922, #20353.

Note: See TracTickets for help on using tickets.