Daily Archives: Sunday, 25th May 2008

WordPress 2.5 – Another Irritation Fixed

Following on from my earlier mutterings, I’ve just found a plugin that fixes things a bit more for me. Category Selector Back to the Sidebar isn’t big, and its result isn’t very pretty, but it does succeed in moving the Categories selector out from under the main section and over to the sidebar.

The intention is to allow people to pick categories without having to scroll. As all my posts live in one category (I prefer to use crazy numbers of tags), I can safely ignore it, and enjoy having the things I need in more plain view.

I might borrow some ideas from this to make some more modifications…

WordPress 2.5 and Cricket Moods

One of my major annoyances with WordPress 2.5 was with the Cricket Moods plugin, whose author is planning to produce an all-new and much spiffier thing rather than an update, which is really cool, and I’m sure it’ll be great. But as he has a life[1], it may be a while before he can devote enough time to the project. All of which left Cricket Moods a bit broken in WordPress 2.5. It actually works perfectly, but the box where you select moods just appears at the bottom of the Write page in WordPress 2.5, far below sections that I never use, way below the fold, and where I found myself forgetting to add moods to my posts. Now as I like to add at least one to every post[2], this was slightly annoying, so I had to do something quite shocking and out of character: I looked at the code. Yes, I opened up the plugin in my text editor and tried to work out what needed to change to make it a bit more WordPress 2.5 friendly.

My first attempt, based on borrowing code from another plugin, managed to put the box into a WordPress 2.5 style clicky thing, but it was still at the bottom of the page, which wasn’t quite what I wanted. Then I saw a reference somewhere to the function used in WordPress 2.5 to add these boxes:

WordPress Codex: Function Reference/add meta box

This gave me the clue I needed. You insert a box with this function:

<?php add_meta_box('id', 'title', 'callback', 'page', 'context'); ?>

I’d worked out the right things to put in most of the values, but the one I’d missed was “context”. Reading the Codex told me that this could be either “advanced”, which would drop the box into the bottom of the lower section of the Write page, or “normal”, which would add it to the upper section, under the Tags and Categories sections. I updated my edits, and woo hoo, it worked. It’s still not quite where I want it, but for a non-coding person it’s as good as I’m likely to get it.

I’ve left a comment on the author’s site explaining what I’ve done, but I’ll repeat it here for anyone who’s interested. Note that these changes will most likely make Cricket Moods crash and burn on versions of WordPress lower than 2.5. A proper coder would write stuff that runs the correct code based on the version being used, but as this was purely for my own use, I didn’t attempt that. Anyway, this is what I did:

I started with a copy of cricket-moods.php version 3.6, and made the following changes:

  1. Added this function on Line 289, just above the beginning of cm_list_select_moods. It could probably have gone somewhere else, and for coding reasons I don’t know about, might have been better somewhere else, but this works:
    function cm_add_moods_box() {add_meta_box('cricket', 'Moods','cm_list_select_moods', 'post','normal');}
  2. Then I changed the bit of code that inserts the box. In the original, this is on line 312, but after adding the first bit it will be line 313. It looks like this:
    echo '<fieldset id="cm_moodlist" class="dbx-box"><h3 class="dbx-handle">'. __('Moods', 'cricket-moods') .'</h3><div class="dbx-content">';

    After adding the first bit, that’s now line 313. That whole line needs to be replaced with the next bit of code. You can either delete it or just make it a comment by adding // at the beginning of the line. Either way, make the new line look like this:

    // echo '<fieldset id="cm_moodlist" class="dbx-box"><h3 class="dbx-handle">'. __('Moods', 'cricket-moods') .'</h3><div class="dbx-content">';
    echo '<fieldset id="cm_moodlist" class="meta_box">';

    Yes, that is a bit simpler, isn’t it? That’s partly because of how the new code works, and partly because I haven’t attempted to do the translation string thingy (if you don’t know about that, you probably don’t want to…).

  3. At the end of the cm_list_select_moods function, around line 342 or 343, depending on your editing, you’ll find this:
    add_action('dbx_post_sidebar', 'cm_list_select_moods');

    Either delete it or comment it out:

    // add_action('dbx_post_sidebar', 'cm_list_select_moods');
  4. Finally, we need to add the code that ties the box in to the Write page:
    add_action('admin_menu'; cm_add_moods_box');

    I added it right at the bottom of the file, just before the closing ?>, so I could find it, but it could probably have gone in place of the line deleted in the previous step.

That wasn’t too bad, was it?

Now save the changed file (keep a copy of the original in case it goes horribly wrong). Upload the new file to your WordPress plugins folder and activate it in the usual way. You should now find the Cricket Moods box lives in a more useful place in your Write page. If it doesn’t work, or it messes up the page, then either one of your edits is wrong, or I’ve made a typo. If you can get to the plugins page, deactivate it and the problem will go away. If you can’t get there, use FTP to delete the edited cricket-moods.php file and replace it with the original, which will work as it did before.

As with anything code-related, I have to emphasise that I have no idea what I’m doing and just fiddle with things until they either do what I want or I give up in despair, so I can’t really answer any questions about this kind of thing. All I can say is that this worked for me…

[1] The fiend!!
[2] It’s a habit

WordPress 2.5 – Progress Report

I gave WordPress 2.5 a bit of a hard time earlier this month, so it’s only fair that I should post my thoughts after living with it for almost a month. After all, sometimes first impressions are misleading…

Well, I’m still not particularly happy with the layout of the Write page. And given the number of posts I’ve made so far this month, I don’t think I can be accused of not giving it a fair test. I’ve managed to mitigate some of the problems by reducing the number of lines in the text box where I type all my nonsense. This is OK for shorter posts, but I miss being able to see more of my text at one time. What I gain from this is being able to see some of the magic boxes below the posting area – those boxes that I would like to have on the sidebar, or be able to rearrange, but currently can’t.

So, after a month, I’m afraid that my first impressions still hold. But things may change: there are some Good Things coming in WordPress 2.6 that might just make me a lot happier, and I’ll talk about those in another post…