Announcing DeadTrees

Today I’m releasing DeadTrees, a WordPress plugin to share the books you read. Get it from wordpress.org or search for DeadTrees in the Plugins > Add section of your WordPress admin.

Features

DeadTrees lets you post the books you read, with or without writing about them, (really, does the internet need to know what you thought of the last mystery you read?). It generates Amazon affiliate links to those books so you, (or I), can make a little money if your readers buy the books, and it auto-fetches the books’ cover art from Amazon so things look cool.

Why?

I have been posting about books that I read for a while now, but ground to a halt when I got lazy & didn’t want to write a whole post about each book, and realized often it doesn’t matter what I think about a book. However, I did want to keep posting at least the te title & author of each book I read, (and so my sister can check to see what I’ve read before giving me a book).

Why write a plugin when there are other plugins to share the books I read? Because the other plugins didn’t do it how I wanted them to. I couldn’t find another plugin that uses WordPress’s Custom Post Types to store books I’ve read, and books are such a perfect use of CPTs that they’re even used as the example in the WordPress documentation!

Support & All That

I’ve put DeadTrees up at GitHub, if you have issues try to submit them there. My contact page is also always available to reach me.

See It Live

DeadTrees is up & running here. Take a look at the books I’ve read.

PHP’s mysql_connect() Reuses Connections by Default

As I mentioned yesterday, I’m doing some work in WordPress right now, and a few minutes ago I tweeted that my custom code is messing with WP’s wp_get_archives() and wp_list_categories() functions, well, I found the problem.

I am including the 4RoadService.com header & utilities files in my WordPress theme, and I am using the same user here on my test server for both the main 4RoadService.com database and the WordPress database. It turns out that when the 4RoadService.com database connection was initialized, since it uses the same connection info as the WordPress database, the existing connection was just reused, (this behaviour, by the way, is well described in the PHP documentation), then when the 4RoadService.com connection was told to use the main 4RoadService database it did, thus switching our one and only connection away from the WordPress database, and making WordPress think that there were no posts on the blog.

Fortunately, there is a quick workaround, just add one more attribute to the mysql_connect() function so it looks like this:

$dblink = mysql_connect($host, $user, $pass, true);

This way a new connection is established, and the WordPress connection is left alone.

I am left wondering why, in the loop, WordPress was able to see my posts, perhaps it establishes a second database connection in there. However, I’m not going to spend the afternoon poking through the guts of WordPress.

Endpoints: A little secret for URL manipulation in WordPress

Today I’ve been setting up WordPress as the News section of a website which loads its pages via AJAX requests whenever possible, but falls back on normal HTTP requests when the AJAX loads are not possible.

The when the AJAX requests are initiated from Javascript, /outputxml/ is added to the end of the URL. This gets translated, with some mod_rewrite magic, to a $_GET parameter called output. /outputxhtml is also possible but since that’s the default it doesn’t get used very much.

After, (mostly), building the WordPress theme I started testing, and as I expected I ran into some problems when /outputxml/ was added to the end of the WordPress URLs. I got 404 errors, which makes total sense. I thought I could get around this by simply doing a little extra mod_rewrite magic, however, it seems there’s not way to simply replace /outputxml somewhere in a url with an empty string using mod_rewrite alone. After some time, I stumbled upon an underdocumented WordPress function: WP_Rewrite::add_endpoint and its friend, add_rewrite_endpoint. These functions make it so that WordPress recognizes /category/post-name/trackback, and /category/post-name/outputxml. Excellent!

I just had to create a plugin, make sure that WordPress wouldn’t kill my $_GET[‘output’] variable, add 1 line to my .htaccess and I was good to go.

References:

And this is what my plugin looks like, (for educational purposes only. I am not distributing it):

function fourRS_outputxml_activate() {
    global $wp_rewrite;
    add_rewrite_endpoint('outputxml',array(EP_PERMALINK, EP_PAGES));
    add_rewrite_endpoint('outputxml',EP_ALL);       

    $wp_rewrite->flush_rules();
}
register_activation_hook( __FILE__, 'fourRS_outputxml_activate');


function fourRS_outputxml_deactivate() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

register_deactivation_hook( __FILE__, 'fourRS_outputxml_deactivate');


/* Makes it so WP doesn't eat my nice $_GET variable */
function fourRS_parameter_queryvars( $qvars )
{
    $qvars[] = 'output';
    return $qvars;
}
add_filter('query_vars', 'fourRS_parameter_queryvars' );

Edit (August 25, 2009): Changed the attrbutes in the add_rewrite_endpoint() function.

Re-Design!

Goodbye to the old Summer Fun theme!
Goodbye to the old Summer Fun theme!

After over two years it is time to say goodbye to the old “Summer Fun” theme.

This new theme has been created in my spare time over the past couple of months. It is designed to highlight what I post. The sidebar, footer, and metadata all fade away unless they’re moused over, there is lots of white space, and with the introduction of ClearType I have updated the fonts to be more like a printed book. The new theme also uses no images!

There will, of course, be some tweaks to be made over the next while as I get some feedback, but for now, enjoy!

WordPress Exploit Scanner should mean Fewer Hacked Blogs

A couple of weeks ago an article about hacked WordPress sites came up in my WordPress admin dashboard.  I hadn’t been paying attention to all of the noise that was apparently going on about hacked blogs, but this article got my attention, and I read it.  I learned a lot about how to see if my blog was hacked, but a lot of it consisted of searching for strings in all of my wordpress files, which would involve downloading them all to my computer.  What a pain in the ass.

Well, that was two and a half weeks ago. Times have changed. Donncha has come out with the WordPress Exploit Scanner, (currently version 0.1).  It does the work for you!  Download it and check your wordpress blog.  I did, (and I came up clean).