scriptygoddess

19 Dec, 2010

WordPress Plugin: Download Post Comments

Posted by: Jennifer In: WordPress|WordPress Plugins

If you run any contests on your blog, and you use your comments to collect entries into the contest – you might run into some difficulty if you get a great number of comments. I was asked by Jyl (MomItForward.com) to develop a plugin that would allow her to download all comments from a post into a CSV. She's been using a very early version of this for some time and gave me the permission, when I had time to do so, to release the plugin to the WordPress community.

This plugin adds a link to the "Edit Posts" view that will allow someone with "can moderate comments" capability (Editor) to download a CSV of all comments for that particular post. This gives an easy one page view of all comments and that can be opened using Microsoft Excel (or similar spreadsheet program). You can then use something like "random.org" to pick a number, and then choose the corresponding row number to decide the winner in your contest.

I hope you find it useful/helpful.

Here's the link on WordPress' Plugin Repository:

Download Post Comments

9 Responses to "WordPress Plugin: Download Post Comments"

1 | Kyle

January 31st, 2011 at 8:50 pm

Avatar

Thank you for this plugin, it saved me time from having to write my own, but your plugin needs at least two tweaks that I have found.

First one is the query. You should update it to
$sql = $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "comments WHERE comment_post_ID = %d AND comment_approved = '1';", $_GET['p'] );

The next would be the image echo next to the post.

echo ''.$numcomments.' <img src="'.plugins_url('/download-post-comments/images/arrowicon.gif').'"';
Notice that you are missing the closing bracket of the image tag.

Update to
echo ''.$numcomments.' ';

As for the rest of the code, the only thing I can recommend would be to read http://codex.wordpress.org/WordPress_Coding_Standards and try and update your code to match the common coding standards within the plugin development community.

If I run across any other issues I'll update you, but other then the above, it seems to be working just fine! Thanks and keep up the good work!

2 | Kyle

January 31st, 2011 at 8:52 pm

Avatar

My apologies. It seems that even with the code tag, a lot of content parsed out.

3 | Jennifer

January 31st, 2011 at 9:05 pm

Avatar

Hi Kyle, Can you email me the changes instead if some of it got messed up? jennifer at scriptygoddess dot com.

4 | Kyle

January 31st, 2011 at 9:15 pm

Avatar

I'm getting an automatic Mail Delivery error at that address.
I did send it to the email account that sent me the notification, so you may receive a reply to scripty [at] scriptygoddess

5 | Jennifer

January 31st, 2011 at 9:18 pm

Avatar

haha. I have too many email addresses!!! I mixed and matched two of them. I got your email so the scripty at scriptygoddess dot com worked. (Oy. It's been a really bad day.)

6 | Michael Brandvold

May 2nd, 2011 at 10:22 am

Avatar

I am hoping to use your plugin on Greg Kihn's official website, http://www.gregkihn.com

I have it installed and active, but on the Edit Posts page I can't find any link to download comments. I am logged in as the admin.

Any thoughts?

7 | Jurgen

May 17th, 2011 at 2:48 am

Avatar

Hi!

Great plugin! The only problem is that I would like to use it to download the comments on a page, not a post. I don't really see how that could work right now, do you have some thoughts?

Thanks!

8 | Jennifer

May 19th, 2011 at 9:00 am

Avatar

It should be possible with a quick little addition (I can try to add that in to the plugin – just don't have time right now…)
Open up the file "download-post-comments.php" in the plugin directory on your server – locate this line:
add_filter('manage_posts_columns', 'download_post_comments_column');
and add this line below the one shown above:
add_filter('manage_pages_column ','download_post_comments_column');
let me know if that works…

9 | Jurgen

May 25th, 2011 at 3:02 am

Avatar

Hi Jennifer,

Thanks for the advice! It did'nt work right away, had to changes some extra stuff in your plugin. But it works for pages now too!

add_filter('manage_posts_columns', 'download_post_comments_column');
function download_post_comments_column($defaults) {
if (current_user_can( 'moderate_comments' )) {
$defaults['comment_user_download_column'] = '<img src="'.plugins_url('/download-post-comments/images/downloadcomments-icon.gif').'"';
}
return $defaults;
}

add_action('manage_pages_custom_column', 'download_pages_comments',10,2);
function download_pages_comments($column_name, $id) {
if (current_user_can( 'moderate_comments' )) {
global $wpdb;
$sql = $wpdb->prepare("SELECT COUNT(*) FROM wp_comments WHERE comment_post_ID ='%d' AND comment_approved = '1';",$id);
$numcomments = $wpdb->get_var($sql);

if( $column_name == 'comment_user_download_column' ) {
echo ''.$numcomments.' ';
}
}
}

add_filter('manage_pages_columns', 'download_post_comments_column');
function download_pages_comments_column($defaults) {
if (current_user_can( 'moderate_comments' )) {
$defaults['comment_user_download_column'] = '<img src="'.plugins_url('/download-post-comments/images/downloadcomments-icon.gif').'"';
}
return $defaults;
}

cheers, jurgen

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements