Join over 55,891 Subscribers Today! FREE UPDATES!
Get The Only Freelancer crash course you will ever need to read!
In recent years blogs have become so popular that and they’re one of the most common ways people get their daily dose of information. It’s not possible for a single person to provide quality content everyday. As a result, major websites are accepting guest authors to provide quality content on a regular basis.
Authors play a vital role in these multi-author blogs since they are responsible for providing up-to-date content for their readers. Once a post is published, the author has to respond to comments, fix the issues and update the content according to the latest trends. As an Author, it is important to respond to user comments quickly. When a comment is made, only the administrator gets the notification email to approve the comments. But there is no default functionality to notify the author.
Authors have to view comments of each post regularly and I can tell you that is very hard if you have written a large number of posts. In this tutorial I am going to ease this task by creating an author comments feed for the comments of all posts written by a single author. Then you will be able to view all the comments in one place. So Lets get started.
Although we can create our functionality in the functions.php file of the theme, it’s always recommended to create an independent plugin for custom functionality. So let’s create a folder called Author-Comments-Feed inside the wp-content/plugins folder and insert the following code to index.php file. It is used to provide information about the plugin.
/* Plugin Name: Author Comments Feed Plugin URI: http://innovativephp.com/ Description: Generate RSS feed for comments on all the posts of a specific author. Version: 1.0 Author: Rakhitha Nimesh Author URI: http://innovativephp.com/about/ License: GPLv2 or later */
Now you will be able to see our plugin in the plugin list on the admin dashboard. So let’s move onto adding our RSS feed.
WordPress provides a default set of RSS feeds for posts, comments, categories etc. Also we are allowed to create custom RSS feeds using the add_feed function. So let’s add our Author RSS feed.
function add_author_comments_feed() {
global $wp_rewrite;
add_feed('wp_author_comments', 'wp_author_comments_feed');
add_action('generate_rewrite_rules', 'author_comments_rewrite_rules');
$wp_rewrite->flush_rules();
}
add_action('init', 'add_author_comments_feed');
Lets move onto creating custom rewrite rules for Author Comments Feed.
If you are using the default URL structure of WordPress (using query strings), you don’t need to worry about this section. This section is essential if the site uses a custom permalink structure. So lets take a look at our author_comments_rewrite_rules function.
function author_comments_rewrite_rules($wp_rewrite) {
$new_rules = array(
'feed/(.+)/(.+)' => 'index.php?feed=' . $wp_rewrite->preg_index(1)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
Now we are ready with our custom rewriting rules and its time to create the Author Comments Feed.
I am going to use “Universel Feed Writer class” library for generating RSS feed. You can download it here.
Once downloaded add the FeedWriter.php file and FeedItem.php file to your plugin directory.
Then make sure to include FeedWriter.php file in the top of the index file. Also we need slight modification to the autoload function in the downloaded library. Following code shows the default autoload function in the library.
function __autoload($class_name){
require_once $class_name . '.php';
}
The code above will try to autoload every class in WordPress as well and will generate errors. So modify the above function with the following code to only autoload the classes related to the library.
function __autoload($class_name){
if($class_name == 'FeedItem'){
require_once $class_name . '.php';
}
}
Now lets take a look at our wp_author_comments_feed function which generates the RSS feed.
function wp_author_comments_feed() {
global $wpdb;
$username = isset($_GET['auth']) ? $_GET['auth'] : array_pop(explode("/", $_SERVER['REQUEST_URI'])) ;
$user = get_user_by('login', $username);
$sql = "SELECT $wpdb->posts.guid,$wpdb->posts.post_title,$wpdb->comments.comment_author,
$wpdb->comments.comment_author_email,$wpdb->comments.comment_date,
$wpdb->comments.comment_content FROM $wpdb->posts inner join $wpdb->comments
on $wpdb->posts.ID=$wpdb->comments.comment_post_ID WHERE
$wpdb->posts.post_author=".$user->data->ID." and $wpdb->posts.post_status='publish'";
$numComments = $wpdb->get_results($sql);
$TestFeed = new FeedWriter(RSS2);
$TestFeed->setTitle('Author Comments Feed of '.$user->data->display_name);
$TestFeed->setLink('http://www.1stwebdesigner.com');
foreach ($numComments as $key => $comment) {
//Create an empty FeedItem
$newItem = $TestFeed->createNewItem();
$description = "Comment Author Name : $comment->comment_author <br/>
Comment Author Email : $comment->comment_author_email <br/>
Comment : $comment->comment_content <br/>";
//Add elements to the feed item
$newItem->setTitle("New Comment on " . $comment->post_title);
$newItem->setLink($comment->guid);
$newItem->setDate($comment->comment_date);
$newItem->setDescription($description);
//Now add the feed item
$TestFeed->addItem($newItem);
}
$TestFeed->genarateFeed();exit;
}
Now we have the Author Comments Feed ready. Every author can access the comments feed using ?feed=wp_author_comments&auth=username or /feed/wp_author_comments/username depending on the permalink structure.
It’s important to notice that this plugin will only work with WordPress default comment system which stores the comments on wp_comments table. Plugin will not work with custom commenting systems like DISQUS.
Now authors have their own comment feed and the problem of responding to latest comments is solved. Lets see how we can improve this by using IFTTT.
Even though we have a comment feed, it takes time to log into your RSS reader and look for the new comments on your posts. So lets see how we can use IFTTT services to get an email directly to your inbox when the comment feed is updated. First create an account in IFTTT.com and log into your account.
Then click on the Create button in the dashborad and you will get the following screen.

Click this and you will get a list of channels in the bottom of the page as shown below.

Choose Feed and you will get the next screen as following.

Choose New Feed Item and you will be directed to enter the Feed URL.

Enter the URL of the feed and you username in the format which I mentioned in earlier section and click Create Trigger button to get the following screen.

Click that and choose a channel as we did before. Since we want to get an email, its better to select Gmail from the list. You will be directed to the following screen.

Click Send an Email to get to the following screen.

Enter your email address and customize the content according to your preference. Finally click the Create Action button.
Now every time the feed is updated you will receive an email to your gmail account.This method will save you a lot of time in responding to comments. Hope you enjoyed it and feel free to share your comments.
Get The Only Freelancer crash course you will ever need to read!
Rakhitha Nimesh is a software engineer and writer from Sri Lanka. He likes to develop applications and write on latest technologies. He is available for freelance writing and WordPress development. You can read his latest book on Building Impressive Presentations with Impress.js. He is a regular contributor to 1stWebDesigner, Tuts+ network and Sitepoint network. Make sure to contact him at www.innovativephp.com or follow him on Twitter
Thursday, August 30th, 2012 15:24
Simply brilliant buddy! Thanks for sharing such a killer tips with us :)
Friday, August 24th, 2012 11:25
It is obvious that single author cant comment all the post that he/she writes. Creating a comment feed for author helps them in connecting with their visitors. Nice post with tutorials “)
Friday, August 24th, 2012 02:32
Blog visitors may not notice an author’s comment right away, though. Highlighting author comments is an easy way to make them stand out. The standard comments template for WordPress themes already comes with a CSS class you can target, so you can give an author’s comment a different background than the others.
If not, then it's time to learn how to:
You can trust 1stWebDesigner to help you become a better web designer!
- Jacob Cass | Just Creative
Just enter your name and email below and click Get Updates!
Natalie
Friday, August 24th, 2012 02:32
Blog visitors may not notice an author’s comment right away, though. Highlighting author comments is an easy way to make them stand out. The standard comments template for WordPress themes already comes with a CSS class you can target, so you can give an author’s comment a different background than the others.
Rakhitha Nimesh
Friday, August 24th, 2012 22:25
Your idea is very good. Actually this feed is intended to use for authors only. Because users will not know the usernames of authors and they can see the comments in the site. I created this feed to notify authors that a new comment is available so that he can respond quickly
Thanks for the comment.
Nahan
Friday, August 24th, 2012 11:25
It is obvious that single author cant comment all the post that he/she writes. Creating a comment feed for author helps them in connecting with their visitors. Nice post with tutorials “)
Arafin Shaon
Thursday, August 30th, 2012 15:24
Simply brilliant buddy! Thanks for sharing such a killer tips with us :)