How to customize WordPress comment notification emails

mail box

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...

1 Response

  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: