WordPress: Solution for sending moderation e-mail notifications to authors

Posted by Pierre Igot in: Blogging
January 25th, 2005 • 8:26 am

It is the day of solutions… Not always pretty ones, but solutions nonetheless.

This one is for the problem I described last week, where blog item authors other than the administrator (myself) were not getting e-mail notifications whenever someone submitted a comment on one of their blog entries that needed to be moderated (i.e. approved or deleted).

At the time, I mentioned that the WordPress documentation about this was rather insufficient. That is still the case, but the more I think about it, the more I believe that what I believe to be a bug on my server is actually the “normal” behaviour.

In actual fact, in WordPress, the administrator is the only one that is supposed to get notifications about comments to be moderated. As I indicated in my previous post, there is a function for sending notifications to post authors (when they are not the administrator), but it is only for sending notifications about comments that have already been approved by the administrator and added to the site.

That is what I gather from a closer look at the actual wp_notify_postauthor function in WordPress’ functions.php file (which is located inside the wp-includes folder. The text in the body of the message that is generated by that function makes no reference to approving or deleting a comment, only to the fact that a comment has been added.

And, in fact, when one of my authors did report that she received a notification once, albeit several hours after the comment was submitted, I believe that what happened is that she received a notification of the actual approval of the comment by me.

See, we are still in the testing stages, so the site is not live and no one is reading it or submitting comments yet, except for us when we are testing the functions. So most of the comments that have been submitted have actually been test comments by me, and I haven’t approved any of them — except maybe once or twice. And that’s the one time when the author did get the notification.

Still, this did not provide me with a solution. According to the WordPress developers, only the administrator should get moderation notifications by e-mail. I don’t agree with this, especially in light of the fact that users other than the administrator can approve or delete comments if their user level is high enough.

So, can this be changed? It turns out that it can be changed, and it’s not even very difficult. All you had to do is edit the functions.php file. Find the wp_notify_moderator function and scroll down to the end of the function, where this line appears:

    @mail($admin_email, $subject, $notify_message, $message_headers);

All you have to do is add the following line immediately after that line:

    @mail("<name@domain.com>", $subject, $notify_message, $message_headers);

where name@domain.com is the e-mail address of the other person you want to notify. You can add as many lines with different e-mail addresses as you want.

It’s a “brute force” approach, because it sends all notifications to everybody. But that’s OK in my particular situation, where it is actually what we want.

I found this particular “hack” all by myself, so I am pretty pleased with it :). Still, I suppose it would be prettier if it could be customized to only send notifications to the administrator and to the actual author of the post — or to those users who have a user level that is high enough to authorize them to moderate comments. But I’ll leave that to someone who actually needs the functionality!

Comments are closed.

Leave a Reply

Comments are closed.