New WordPress Plugin: Link This Bookmarklet

I’ve just uploaded a new WordPress plugin that was inspired by my wife setting up her new site.  She was adding people to her blogroll and having to keep copying their urls and going into the WordPress admin section.  This was getting tedious, so I’ve made a plugin that creates a bookmarklet you can add to your browser that pops up a form to add the page you’re on directly to your site’s links.  It’s similar to the built-in ‘Press This’ bookmarklet, except for links instead of posts.

Link This Bookmarklet

There is a more detailed description of the plugin & how it works on the plugin page, and you can install it directly through your WordPress admin section or download it from the WordPress Plugin Directory.

New beta for the FriendFeed Comments plugin

For anyone who’s game, and especially for anyone who’s been having problems with the FriendFeed Comments plugin, I’ve just checked in a new beta release that you can download.  It’s not available through the WordPress auto-updater yet because it’s not been tested sufficiently.  So if you’d like to help out you can grab it here: http://downloads.wordpress.org/plugin/friendfeed-comments.1.6.0beta.zip

There aren’t any major visible changes.  There’s a couple of tidy up changes eg. I removed some inline styles that I should have moved into the default stylesheet, but the major changes are behind the scenes.  Some people were having issues with the plugin not retrieving the information correctly and it seemed to be an issue for people with a large number of posts & comments.  So this new version now stores the data in a custom table on your WordPress database.  This should make things much more efficient and hopefully less error-prone.

If you do install the new update you must deactivate & re-activate the plugin, then go to the settings page & click ‘Save Changes’ before it will work.  If you don’t the table won’t be created and it won’t work.

If you can help out with the beta testing it would be much appreciated.

Showing trackbacks with Disqus

http://media.disqus.com/images/global/disqus-logo.pngCurrently one of the limitations of using the otherwise great comments service Disqus is that it doesn’t allow you to display trackbacks/pingbacks.  Apparently this will be fixed in a future release of the Disqus WordPress plugin, but for now it’s not working.

The trackbacks you receive are still stored locally in your database, despite them not being displayed, so you can access them. However there isn’t a built-in way to access just the list of trackbacks. Trackbacks are stored as comments in the wp_comments table and are identified by a comment_type of either ‘trackback‘ or ‘pingback‘. (For our purposes here, there’s no real difference between the two. For more info on what the actual difference is, see this page) So, if you wanted to you could write up a bit of PHP that pulled all the trackbacks out of the database & displayed them on your blog, but for a lot of people this is a bit much.

If you look on this page (the FriendFeed Comments Plugin page), you can see a list of the trackbacks that page has received. It’s a very simple list, I’m not displaying the text snippet that usually comes with trackbacks, but that’s just personal preference. If you’d like to be able to display your trackbacks without having to worry about writing code yourself I’ve got a really simple plugin that lets you do this here. The plugin adds 2 functions, get_approved_trackbacks & trackbacks_templateget_approved_trackbacks takes the post id as an argument and returns a list of the trackbacks that have been approved (moderated) for that post. trackbacks_template is essentially an additional template tag to be used in the same way as comments_template() is used on the single.php template file.

So for example, if you wanted to display the trackbacks before the comments, download & install the plugin. Then open up the single.php template file for your site & find the line <?php comments_template(); ?>. Stick <?php trackbacks_template(); ?> on the line above it. This will display the trackbacks as an unordered list inside a div with the id "trackbackslist" with a h3 heading "Trackbacks" above the list. However if you’d like to style it differently, it will also look for a template file called trackbacks.php in your template folder. If it finds that it will use that to render the trackbacks.  This is what I’m doing here so as to not display the trackback text.  By default the plugin will display that too.

Obviously this is an advanced option, and only for those familiar with HTML & PHP.  For those people, the plugin provides a variable called $trackbacks which is an array of comment objects. The code that I’ve used to display the trackbacks by default is contained in a file called ‘trackbacks.php’ in the plugin folder, which you can copy into your template folder to use as a starting point for styling your own list.

Hopefully Disqus will sort out what it’s going to do with trackbacks, according to Daniel from Disqus it’s coming soon.  I’m pretty happy with their service, they’ve been really responsive to any support requests and they’ve had pretty solid uptime.  The lack of trackbacks isn’t really a big deal to me, but I do like to show who’s discussing my posts. As usual please leave comments / bug reports on the plugin’s page.

Overcomplicating the issue

One of the main issues that some people have been having with the FriendFeed Comments Plugin is that sometimes, seemingly randomly, it will fail to match up a post with the information from FriendFeed.  There are a couple of reasons why this does happen, but the problems all centre around the fact that I have to use the post title to match up the details because there’s no other uniquely identifiable piece of information available.

This is of course a problem when people edit the title, either due to a typo or a editorial change.  Also there seems to be some string encoding issues, especially around the 32,000 different characters that can render to look like an apostrophe.    I’ve spent quite a lot of time trying to strip out the special characters and normalise the titles so I can be sure of getting a match between what’s on the blog & what’s coming back from the FriendFeed API.  I even tried just stripping out non-alphanumeric characters, but then I had a complaint from an amazingly patient person who’s site was using Cyrillic.  So what I’ve got now is a rather hodgepodge solution where it tries to strip out as many characters as possible, then does an md5 hash on that to use as the id, and some people are still having issues where, for no apparent reason, the posts won’t match up.

Continue reading

New release for the FriendFeed Comments WordPress plugin – remembering your details

I’ve just checked in a new version of the FriendFeed Comments plugin, which you can download here.  If you’ve already got it installed it should be showing up that an update’s available any moment now.

There’s a lot of code tidy ups and debug improvements, but the major change is the addition of the ability to remember your FriendFeed username & API Key when you comment on or like a post.  There’s now a ‘remember’ checkbox under the API Key field (which is now password masked, like it always should have been!).  If you tick that, it will drop a cookie onto your computer which means you don’t have to keep typing in your username & API key for that blog.

An important security note: the cookie doesn’t contain any identifiable information in it.  It just has a hash key value that is used to look up your username & api key in the blog’s database (which is stored in plain text in the blog’s database).  There is no way through the plugin for the site owner to see your API Key, but if they open their database directly, it is possible.  As in any other case, only share your API key with sites that you trust.  If you don’t tick the ‘remember’ box, your username & api key will not be stored anywhere.

As always, try it out here and then give it a go on your site if you like.  Any problems, please let me know.

FriendFeed Comments WordPress plugin1.4 release

I’ve been a bit inspired over the last week to do some fairly major updates to the FriendFeed plugin.  Thanks to some helpful suggestions and feedback from a number of people, I’ve added a bunch of new features and fixed some dodgy code that was in the previous versions.

The biggest change is that you can now comment & ‘like’ a post directly from the post itself without having to go to FriendFeed.  This is done using a bit of AJAX (via Prototype). The user puts in their comment, their username & their FriendFeed API key.  The API key is never visible to the site owner, it’s passed directly through to FriendFeed and then discarded.

image

This form is turned on by default, but can be disabled in the admin section if you don’t like it. Also, because of this change, the plugin will now display on every post, whether there are comments or likes on it or not.

The other changes are:

  • You can now edit the ‘headline’ text that displays. ie the "On FriendFeed, this post was liked by x people and commented on y times".  You can now put whatever you want there, and it will replace the tokens {comments} & {likes} with the number of comments & likes.
  • A default stylesheet is now included, to get you started on styling the plugin’s content.  It also can be disabled in the admin page, and you can see what the stylesheet looks like here.
  • The plugin can now be set to have the FriendFeed comments & likes be visible by default.  Currently the default is to hide them and only show them when the user clicks the ‘show’ link.
  • Also, based on the points I made in my post about self-cleaning WordPress plugins, the admin page now has a ‘delete plugin’ button.  This is will remove all trace of the plugin from the WordPress database, so you can then deactivate the plugin knowing it hasn’t left anything behind.  Needless to say, only use this if you want to completely remove the plugin, not just disable it temporarily.
  • Numerous bug fixes & tidy-ups.  I’ve replaced my bespoke javascript to hide/show the comments with Prototype too.

So, if it hasn’t already turned up in the Automatic Updates list, grab the new version from here.  As always please let me know what you think & how it can be better.

Writing self-cleaning WordPress plugins

Don’t you just hate it.  You install a program on your computer to try it out, then when you go to un-install it, it leaves files scattered all over your system.  Whether it’s in the application folder that it can’t delete, or in the Application Data folder or system32, it’s not easy to find a program that cleans up after itself properly.  I’ve got more of a chance of getting my kids to tidy up the lounge room after they’ve got all the Lego out.

This issue isn’t just limited to Windows applications though.  I’ve noticed the same problem with a lot of WordPress plugins.  It may just be leaving a couple of config options in the wp_options table, or it may be as much as leaving multiple custom db tables behind or even files in the WordPress install folder.  I’m of the opinion that once you remove a plugin, it should be gone without a trace.

Now, for plugin developers, WordPress provides a simple way to do this.  The register_deactivation_hook() method lets you register a function to be called when your plugin is deactivated.  In there you can put any cleanup code to remove options, tables files, etc.

But…

This is not without it’s problems.  Often plugins require you to enter some complex config information or they may build up a history that you may not want to lose (eg. a spam filter that learns from what you mark as spam).  Sometimes you need to disable plugins temporarily, in fact the WordPress update instructions say that you should deactivate all your plugins prior to upgrading.

Also, the automatic plugin updates system introduced into WordPress deactivates plugins before it installs the updated version.  So if you put the cleanup tasks into the deactivation hook method, all the user’s settings would be gone after updating.  This really isn’t a good option.

What would be better is if the WordPress plugin admin page had 2 buttons for each plugin: deactivate & uninstall.  Deactivate would do what it does now – turn off the plugin, but leave it in place.   Uninstall would completely remove the plugin, including deleting the plugin file & firing a separate uninstallation hook callback.  Developers could then put all their cleanup code in there, with no fear that users were going to lose settings during an upgrade.

What to do for now

I think for the time being it would be best if developers included a ‘remove all data’ button on their plugin’s options page (if it has one).  This button would remove all trace of the plugin (other than deleting the plugin itself) so that the user can then deactivate it.  This button should probably be restricted to admin users and have some form of confirmation on it. I’ve added a button to do this in the latest release of the FriendFeed Comments Plugin.

There’s already a post about this ideas section of WordPress.org, and a discussion about it on Weblog Tools Collection.  I’m hoping that this gets noticed, because it would be great if developers had a simple way of tidying up after themselves.

If this is something that matters to you, please go vote up this idea on WordPress.org.

FriendFeed Comments WordPress plugin 1.1 release

FriendFeedI bit the bullet & updated the FriendFeed Comments plugin to version 1.0.  I then noticed a couple of other things I needed to do, so I immediately updated it to 1.1.  So lets just say we skipped 1.0 Ok?

No real functionality changes, just a bit of housekeeping and admin tweaks.  The plugin will now warn you if you haven’t entered a FriendFeed nickname in after activating the plugin.  Also, after saving your nickname on the options page, it puts up a reminder to put the <?php wp_ffcomments(); ?> tag in your single post template.

So get it running & let me know what you think!

A few updates for the FriendFeed plugin

Thank you to everyone who’s installed the FriendFeed plugin.  The feedback has been very helpful. I got svn access for the WordPress Plugin hosting, so the plugin now exists on the WordPress plugins site.  The upshot of this is that it will now be included in the WordPress automatic updates, so if your version of WordPress supports that, you should start seeing updates for it on your plugin pages. 

Speaking of updates, I’ve just checked in an update that shows the likes as well as the comments.  So you will now get a list of the people who ‘liked’ your post as well as the comments. I’ve also tweaked the HTML it generates a bit, so if you’d setup some CSS rules around the plugin, you might want to check they all still work after updating.

image

I’ve got some default styling rules that you can apply to get started, otherwise the plugin is just going to give you two vertical lists, which probably isn’t what you want

#togglefriendfeedcommentslink { color: #333; font-size: 10px; font-weight: bold; }
#friendfeedicon { float: left; border: none; padding: 0 4px 0 0; }
#friendfeedlikeslist ul, #friendfeedlikeslist ul li { display: inline; }
#friendfeeddiscussions { margin: 10px 0 0 0; clear: both; }

Can I recommend the Cross-theme Stylesheets plugin to make this simpler.  You can create a stylesheet just for this plugin that can be edited inside the WordPress admin section, independent of the theme’s styles.

Update: Just got my first TechCrunch link!

FriendFeed Comments WordPress Plugin

Well, FriendFeed released their API yesterday, along with pre-written php & python libraries.  It’s a really good API, got access to all the data you see on the site.  So I’ve written up a WordPress plugin that will pull back comments from FriendFeed & show them on your site.  This plugin will allow you to display on your own site the comments that people make on FriendFeed about your post. 

I keep trying to think of a more succinct way of writing that but I can’t.  I always sounds more confusing than it is. See the plugin page for more details, this is an early beta I can’t stress that enough.  It will have bugs, it may very well break. 

image

Anyone who is willing to help beta test would be very welcome, you can download the zip file here. Unzip that into your plugins folder & activate it.  You’ll then need to go into the options (or settings if you’re running WP2.5) and click on FriendFeed.  Put your FriendFeed nickname in & save.  You’ll then need to drop the new template tag <?php wp_ffcomments(); ?> on to your single post template somewhere inside ‘the loop’.  I put mine just above the <?php comments_template(); ?> call.

Much thanks to Corvida for being my first guinea pig tester.  It seems to be working on her site, and she gets a lot of comments!