Posts Tagged ‘hacking’

Upgrading to WordPress 3.3 – the missing “Format” box

Friday, December 16th, 2011

I recently installed WordPress 3.3 for a client, and I was very impressed. Specifically I was excited about tinkering around with the “Format” box, which allows you to post in a variety of formats, including, “Status”, “Gallery” and the regular post format “Standard”.

I wasted no time upgrading this site to WordPress 3.3, but no fun format box. I poked around at options and Googled, to no avail. Most suggestions seemed to revolve around some browser problem, but I could see it on the other site, plain as day, so my browser was obviously capable of displaying it.

For lack of a better idea, I started grepping. I used Firebug to get the id attribute (“formatdiv”), figuring there would be a finite number of instances in the code. Indeed, there was exactly one. It was in wp-admin/edit-form-advanced.php. There were two relevant lines:
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) )
    add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core' );

This alerted me that it was a problem with the theme, which unsurprising considering that I’m still using a customized version of the 2009 default theme. I knew it worked in the latest theme, twentyeleven, so I went to that directory and grepped for ‘format’ and braced myself for the worst. Once I eliminated the CSS files, it was easy to hone in on line 104 of functions.php
add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) );

This takes place in a function called setup. I went over to my theme and looked for a similar function in the functions.php file. It did not have one. I pasted it in toward the middle of the file and hoped for the best. The format box appeared like magic. I haven’t actually tinkered with it yet, but I wanted to write up my experiences – before I forget them – so that someone else with an old theme can bring some new magic into their WordPress experience.

Hacking Tracks to accept shorter usernames

Monday, October 18th, 2010

I’m looking at Tracks/Shuffle to manage to-do lists on my phone/computer. I’m scouring the tubes for one that doesn’t involve me handing my data off to someone else. I like Shuffle because it can synch to any Tracks server you specify, and since Tracks is free software, it’s easy to install on any server.

In an effort to be able to use my usual login (kj), I H@X0R-H@X0R-H@X0R-ed the code to lower the minimum login from 3 to 2 characters. It’s not rocket science, but I hope it’ll save somebody else a bit of grepping:

In app/models/user.rb, line 115, change

validates_length_of :login, :within => 3..80

to

validates_length_of :login, :within => 2..80

In spec./models/user_spec.rb, line 81, change

it_should_validate_length_of :login, :within => 3..80

to

it_should_validate_length_of :login, :within => 2..80

If you’re feeling really ambitious, you could even change the error messages to be accurate. In test/unit/user_test.rb,. line 87:

assert_error_on u, :login, “is too short (minimum is 3 characters)”

to

assert_error_on u, :login, “is too short (minimum is 2 characters)”

Again in test/unit/user_test.rb,. this time on line 107:

assert_errors_on u, :login, [“can’t be blank”, “is too short (minimum is 3 characters)”]

to

assert_errors_on u, :login, [“can’t be blank”, “is too short (minimum is 2 characters)”]