Quite some time ago, I revealed to the world my first attempt at a WordPress plugin: Coming Soon. This was a very basic thing that just listed the titles of all draft posts. This is the sort of thing that’s of little or no interest to most WordPress users, but I like to have it in my sidebar to tease readers with hints of things to come, and to remind me of things I need to get on with writing.
The first version had everything hard coded – if anyone wanted to use it for their own purposes, they’d have had to edit the PHP, which was a bit messy. A later version actually used parameters for the function, which would have made things a little easier, but still wasn’t that friendly. But as I was the only one using it, this didn’t seem all that important.
But on Friday evening, I was looking at the WordPress Support Forums when I saw someone asking for advice on developing plugins, which led me to this really nice article by Leonid Mamchenkov on how to make options pages for WordPress plugins, and this piece by Mark Jaquith on how to make such things more secure.
And so I started fiddling. And, err, several hours later, I had a new version of my plugin, which has an options page for setting the title for the section, the text used for untitled posts and the HTML tags that surround it all. By default, the plugin’s output is set to be an item in an unordered list. The heading is a <h2>, and the titles form an unordered list. That should work for the sidebar in most WordPress themes, but if it needed to be in a <div>, or some other formatting, then changing it is now a simple matter of changing the options.
As it’s pretty much a new plugin, I decided to rename it to the rather more descriptive List Draft Posts, and changed the function name to match.
If this looks like something you would like to use, you can download it from the official WordPress Plugins Directory. Woo.
Unzip and upload the lcb_list_draft_posts.php to your WordPress plugins folder. Activate the plugin in the usual way, then look at the List Draft Posts page under Options. Unless you have special requirements, you will probably only need to change the Heading and Description for untitled drafts options. Click the Update options button to save your changes.
Include the following code at a suitable point in your sidebar:
<php if (function_exists('lcb_ldp')) lcb_ldp();?>
Create a new post, save it without publishing and you should see a list in your sidebar. If there are no draft posts, nothing should appear.
Time passes, and all that. I have since created a widget version of this plugin.
Add a comment to this post, and I’ll look into it as soon as I can. I should mention that I’m not really a coder, so this plugin may not be doing things in the best or most efficient manner, and may drink all your wine or eat your chocolate when you’re not looking. This version has only been tested on WordPress 2.3, but it should play nicely with anything above WordPress 2.0.x.
Until now, I hadn’t realised just how nifty WordPress’s system for allowing plugins to add themselves into the admin interface was. Using the instructions I mentioned earlier, a non-coding person like me was able to make it work with only a few mistakes along the way. Of course, writing more complicated and useful plugins is another matter altogether, and is best left to people who actually know what they’re doing.
 Note to UK readers: this article uses a slightly unfortunate expression for a number used once. This has caused some amusement. It’s that thingy about two countries separated by a common language again…