BookLinker Plugin: giving the gift of choice to readers

I’ve just written my first major WordPress plugin, BookLinker. It was developed for another of my websites, which features quite a few book reviews; the philosophical reasoning behind it is here. But it was also an interesting little glimpse into the WordPress programming paradigm.

The plugin’s goal was to make it easy for me to switch Amazon affiliate links, or augment those links, with links to other book sources. It was prompted by the “#amazonfail” fiasco of a month ago, but the need for such a tool goes deeper than one incident. I want to encourage people to buy books from other places, like Powell’s or IndieBound, or to get them from their library, but the thought of changing all those Amazon links was daunting.

My original thought was to write something that would go into each blog post with an Amazon link and change it to an IndieBound or Powell’s link. But as I looked into the variety of link formats that Amazon provides, and the number of links on my sites, that seemed a more dangerous way to go: it would be difficult to back out a data change like that.

So my second thought was to make the changes on the client side, in JavaScript. This let me do most of the heavy lifting in a language that I’m at least familiar with, using PHP just for the plugin framework and configuration, and it also makes backing things out or tweaking the functionality a lot simpler than a data change would have been.

Consequently, there’s not a lot of PHP in this plugin. All I really had to learn was how to collect, save, and retrieve user configuration variables, and then emit those variables onto the page for the JavaScript piece to take over. And from what little I saw of PHP to accomplish this, I’m glad there wasn’t much; it reminded me of the bad old days of early JSP coding, when people would plug JDBC code and huge scriptlet blocks into their pages, tiered architecture be damned. I have a new respect for people who can take a scripting language with limited tooling and turn out a robust and powerful tool like WordPress.

I like the WordPress plugin architecture. It’s very easy to use the “hooks” and extend the functionality of the core system, which makes for a rich and varied ecosystem. This is certainly one of the best arguments for open architecture as well as for open source.

The thing I like most about this plugin is the UI. I was able to reuse some concepts from the last professional project I had, and build a nice little modal window to hold the collection of links.

You can see it in action here, with this link to Effective Java (2nd Edition) (Java Series); buy it from Amazon if you must, but you can’t blame me for limiting your choices.

2 thoughts on “BookLinker Plugin: giving the gift of choice to readers

Comments are closed.