How to customize WordPress comment notification emails

WordPress comments have been the part of the built since its inception and as WordPress has evolved consistently with need of time and technologies, so has the commenting system. WordPress has come a long way from starting as a blogging platform to be more like an application framework which acquires almost 24% of the whole web till date and comment system has evolved equally being an integral part of WordPress. Keeping with the evolution, with WordPress version 4.4 there would be a change in the comment section structure and henceforth comment textarea would come first, followed by name, email and website, by default.

While working in a food guide project, which has like thousands of posts and hundreds of users, ends up getting hundreds of comments everyday, resulting in filling up my clients mailbox with the moderation/notification mails. As the client and the team logs in almost every day and moderates the comments, they wanted to get away with the emails they were getting. This blog is all about how I did it and what else can be done.

Comments moderation and new comment notifications can be enabled and disabled from the Settings >> Discussion. You can check more details about this in the codex.

As a developer, I am always keen on looking into how much can we customize some functionality with more options. Lets look into what we can do more about the comment moderation and notification emails.

After looking keenly, I found there are two filters comment_moderation_recipients and comment_notification_recipients which can be used to do the trick. comment_moderation_recipients can be used to filter the email ids which receives the moderation mails for comments and comment_notification_recipients can be used to filter the email ids which receives the new comment notification mails

We can customize the functionality in various ways, firstly is what my client wanted, and that was to completely stop moderation/notification mails from being fired. You can do this from the following snippet.

In the above snippet, we are returning an empty array for $emails which is further checked before the control goes to the mailing functionality and as a result of which you get saved from bloating your inbox with moderation/notification mails.

Second way to customize it is to send all the mails only to the site administrator and we can do that with the following snippet

Third way can be sending the mails only to the post author and that can be achieved from the following.

Here we are looking for the post author and also if he/she has the required permission and if yes, that email would get added to the array and receives the mail moderation/notification mails.

I can now think of a fourth and last way of customizing this, which is by sending all the mails to another mail id which is not associated with the site. There may be an instance where you want to keep a tab on the moderation/notification mails but not with the email id your administrator/author user is logged in with. Lets see how to get this done

With this I have tried to explain how we can customize receiving the moderation/notification emails for comments. Use these snippets in the child theme‘s functions.php file. Let me know if there is any other way you want to customize it in the comments below.

facebook-profile-picture

Maruti Mohanty

I am a happy go lucky WordPress Developer, who loves biking, movies and learning different languages

   

You may also like...

19 Responses

  1. Laurie says:

    Hello, let me pick your brain. We don’t have our website up yet … I’m doing a little advance research. Eventually our site will have several individuals doing comment moderation — each moderating a different post category. Can comment_moderation_recipients be used to distribute comment moderation emails by category? I’m new to self-hosted WordPress and a beginner with filters and hooks; how would that be done, basically?

    • Maruti Mohanty says:

      Hi,

      Yes, this seems possible. As the comments are associated to a post, we can get the category out of it too :).

      Thanks

  2. Everything is very open with a very clear clarification of the challenges.
    It was truly informative. Your site is very helpful.

    Thank you for sharing!

  3. Sam says:

    Thanks for this, it’s exactly what I was looking for. I used your 4th example and specified 3 emails to be notified when a new comment is posted. But it seems that when I leave a test comment the website is very slow to acknowledge the comment. When I remove the code and submit another test comment the website is very responsive. Any thoughts to this? Additionally, I don’t know much about php functions…what do the 11 and 2 on the last two lines specify?

    Thanks

  4. Bobby says:

    Very interested in option 1, but is there a way to add only certain email addresses to the array? For example, send emails to everyone EXCEPT joe@example.com and john@example.com?

    • Hi Bobby,

      You can definitely write codes to create an array excluding the emails you don’t want to send the notifications to and then use that array in my above snippet.

      Hope it help!

      Thanks

  5. Massage Lovers Blog says:

    Howdy! Would you mind if I share your blog with my myspace group?
    There’s a lot of people that Ithink would really enjoy your content.
    Please let me know. Many thanks

  6. Carlos M says:

    Gracias pana!
    Thank you!

  7. scryde.ru says:

    Ability to protect the comment author s information in the moderation email. This functionality already existed for the author email.

  8. I’m a fan of editing code and getting things done quickly that way, but you’d think it’d be much easier if someone could create a simple plugin to make this much faster and easier to do right?

    • Maruti Mohanty says:

      Yes, I think plugin makes things easier to use, but then it depends on how the plugin is build and if it does what I need (believe me every use has unique requests;) ), I dont think everything works with “one size fits all” 😉 So if you feel like creating a plugin, go for it 🙂

  1. May 18, 2016

    […] function se_comment_moderation_recipients( $emails, $comment_id ) { // 승인 대기 중 댓글/새 댓글 알림 비활성화하기 $emails = array(); return $emails; } add_filter( 'comment_moderation_recipients', 'se_comment_moderation_recipients', 11, 2 ); add_filter( 'comment_notification_recipients', 'se_comment_moderation_recipients', 11, 2 ); // Source: sourcexpress.com […]

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: