Importing Your Flickr Comments to Your WordPress Blog

If you go to my photoblog, you’ll notice that my pictures have a lot of comments that are actually comments on that photo from my Flickr photostream (2023 edit: I no-longer surface comments on the site).  Pretty cool, eh?  I achieve this by using a WordPress plugin called Live Flickr Comment Importer that lets you add a photo’s flickr ID to a custom field in a WordPress post, then on the next load of that post, it pulls all the comments for that Flickr ID from Flickr and creates WordPress comments from them.

The only drawback to this plugin as originally written by the developer is that the “author URL” of the commenter linked back to that comment on Flickr.  Which, in my opinion, is useless.  I’d much rather see their photostream rather than a comment on my own photo.  So I decided I’d fix this problem.  I started looking at the code and discovered that the way the developer was determining if a comment was already pulled was if the URL for the comment already existed in the WordPress database comments table:

$test_dupes = $wpdb->get_results( “SELECT comment_ID FROM {$wpdb->comments} WHERE comment_author_url='{$comment[‘permalink’]}'”, ARRAY_N);

So, basically, they were using the comment_author_url as the unique key for determining and rejecting duplicate comments.  This works, but I wanted to use comment_author_url to store the commenter’s photostream URL.  But just shoving their photostream URL into that field would cause the function that determines duplicates to break, since a Flickr user might comment on any of my photos more than once.

Fortunately, the WordPress comments table has another (almost) unique field:  comment_date.  If I used this as a unique key, the only time that I’d miss importing a comment from Flickr to WordPress would be if two Flickr commenters posted their comments at the exact same second as each other.  I could live with this possibility, as it was close enough to zero that it might as well be zero.  So I modified the code a bit and got my modified version of the plugin working.  If you want to use it, you can download my modded version here.

 

Questions? Comments? Concerns?