Add New Headers to WordPress Plugins or Themes

I’ve had a few patches committed to WordPress core in the last few versions, and have sadly neglected to do writeups about them so that others could take advantage of the new features. I hope to remedy that in the next few posts. First off, WordPress 2.9 has a new feature that allows you to add to the list of headers that are checked when you run either get_plugin_data() or get_theme_data().

For example: Let’s say you want to make a plugin that works with other plugins. For other plugins to be compatible with it, however, they need to provide some new piece of information, and you want to do this with a custom header. So we’re going declare a new plugin header. Let’s call it… oh…. “Demo Header”. Here’s the code; just drop this in a plugin and activate:

function plugin_header_demo( $extra_headers ) {
	$extra_headers[] = 'Demo Header';
	return $extra_headers;
}
add_filter( 'extra_plugin_headers', 'plugin_header_demo' );

Pretty simple, eh? What we’ve just done is added “Demo Header” to the list of headers that WordPress will check for when get_plugin_data() is run. Now, along with Name, Version, Author, and so forth, a value for Demo Header is returned as well.

Note that this is only for cases where you want any plugin checked for this header. This changes the get_plugin_data() function and takes effect every time that function is run, on any plugin.

Want to do it for themes? The code is almost identical:

function theme_header_demo( $extra_headers ) {
	$extra_headers[] = 'Demo Header';
	return $extra_headers;
}
add_filter( 'extra_theme_headers', 'theme_header_demo' );

Note that this does not allow you to alter the pre-existing headers in any way. You can’t, for example, remove the “Name” header.

Personally, I intend to use this for a third-party update check plugin, which will also be incorporated into Strider Core. For that use, I’ll add an “Update URL” header (or similar).

Next up: How to define your own custom get_XXX_data() function that works like the ones for plugins or themes.

Hackbook finale

In between trick-or-treaters I spent today finishing up the repairs to my new/old laptop. The first optical drive I ordered was DOA, so I had to order a new one. Did the swap today. Took a little testing and such, but I now have a fully operational system, (which is nice).

In the end, a little work and willingness to crack the sucker open got me a $1,100 laptop for about $500. Sometimes its nice to be a geek. ;-)

Hackbook

My laptop has been a bit long in the tooth for a while now. It’s a 12″ Mac Powerbook G4 circa 2003. It actually runs OS 10.5 pretty well, which is impressive considering it originally came with OS 9 (that’s — count ‘em — 6 operating systems ago). The most noticeable issue is that it struggles to play video such as YouTube, and if I’m working with a particularly large file (150+ MB) it struggles to handle it.

So I needed a new one, but didn’t want to drop a grand on it. What to do? Well, I found a fixer-upper on eBay for just over $400. Impressively, it’s last year’s model Macbook with maxed out RAM and a good size hard drive. The down side is that it lacks an optical drive, and the keyboard is en Español.

Got the computer in the mail Tuesday. Thanks to “Target Disk Mode” via Firewire, I was able to wipe the drive and install the OS without an optical drive. Had a small hiccough transferring my old data from my Time Machine backup, in that I had forgotten that my backup doesn’t include my applications. Re-doing the transfer from my bootable backup drive fixed that nicely.

So — I’ll be putting about another $100 into the computer, as I got an English keyboard assembly for $30, and an optical drive for about $75 (both on eBay). I even found an online auction for the *brackets* for the optical drive, which is handy since the computer I bought had the drive completely removed (“it was making a funny noise” I’m told).

So now I get to do surgery. Cool! :) I replaced the hard drive in the Powerbook a couple years back, so I have a bit of experience with cracking open laptops. Should be an interesting exercise, involving steady hands and very, very small screwdrivers.

Every Halloween costume you ev…

Every Halloween costume you ever had was a failure compared to this: http://bit.ly/hLfbY (via @TheBloggess)

Virtual Multiblog 2.6.1

Just released Virtual Multiblog v2.6.1. The primary new feature in the 2.6 line is auto-plugins.

That is, you can specify plugins that are automatically activated for all (or just some) blogs.

Check it out!

Mac OS 9 lives!

Mac OS 9 lives! And it has a browser: http://classilla.org/

An ode to long URLs

An ode to long URLs – and a suggestion or two: http://bit.ly/syESq

10,000 words advocating “sub p…

10,000 words advocating “sub plugins” for WordPress, only to discover I’ve just reinvented something called “Interfaces” http://bit.ly/2rdWQ