Emailing Comment Authors
Overnight, I worked on extending my blogging software so that it emails all comment authors in a comment thread, whenever someone posts a new comment to that thread. I see that other blogs do this and was disappointed that WordPress does not generate these notifications by default. This could be a problem in that people who post comments are not notified when someone else replies. Thus, the original poster may never discover that someone followed up with a comment, because they may forget to visit the blog again to check. So I’m hoping that adding this emailing will entice people to return to the blogs more often.
To that end, I found a plug-in that does something similar; although for each new comment, it apparently emails only the person who posted the last (most recent) comment. It does not email all comment authors in the thread, which is a shortcoming in my opinion. But, in its favor, this plug-in (the ReplyMail WordPress plugin) allows the blog administrator to customize the formatting of the email messages it creates. Plus, it supports template tags, which provide easy control over the content of said messages. So I’d like to use this plug-in, but modify it slightly to email everyone in a comment thread when a new comment is added.
Unfortunately though, upon installing ReplyMail, I discovered that it does not generate any email. I’ve verified that the plug-in is indeed executed each time I post a new comment. Nonetheless, it sends nothing at present because it deems all comments which I’ve tried replying to as being unapproved, though in fact, they are indeed approved.
So, in the comments below, I’ll track my progress toward getting this new functionality functioning correctly. I hope you’ll enjoy this software development journey as much as I will.
April 25th, 2010 at 8:53 pm
Located some code in the comment-template.php WordPress file that retrieves a list of comments for a given post from the database. I’m copying that code into the ReplyMail plug-in.
However, that code does not run in the plug-in. Apparently the $wpdb variable has not previously been defined at the time this plug-in is executed. So I’ll investigate how to initialize things so that access to the database through $wpdb has been properly established when the plug-in starts up.
May 11th, 2010 at 9:30 pm
08:40 PM: Wrote more code for a plugin that will provide additional email support on my blogs. Not much code written; much more time spent reading PHP and MySQL manuals.
11:40 PM: Continued work on setting up a plug-in that will email anyone who’s made a comment on a particular post, whenever a new comment appears. So far, I’ve successfully assembled the list of target email addresses. Tomorrow, I plan to write the code that sends them the email, which will provide a link to the latest comment in the original post.
May 12th, 2010 at 8:04 am
I devised the SQL code to retrieve a list of email addresses of all the comment authors for all approved comments on the current post:
$emailAddressList = $wpdb->get_results($q = $wpdb->prepare("SELECT DISTINCTROW comment_author_email FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = 1)", $post_ID), ARRAY_N);Now, I’m ready to generate the email messages to notify these authors when someone posts a new comment on the current post.