Dougal Campbell's geek ramblings

WordPress, web development, and world domination.

Suggestion: WordPress Option Namespacing

I happened to be poking around in my database a while ago, particularly in the WordPress ‘options’ table for this blog. There’s an awful lot of cruft hanging around from old plugins that I don’t use anymore. I cleaned a few things out, but something hit me as I was perusing all those options: I can’t always tell which options belong(ed) to which plugins, themes, or to the WordPress core.

In many cases, plugin authors tag the option names in a way that you can figure it out. For example, Alex King’s Twitter Tools plugin uses a prefix of aktt_ on all of its options. And many other plugin authors similarly use a prefix of some sort that identifies the author and/or plugin. But it’s very inconsistent.

I would like to suggest a formal namespacing scheme which might help with option management in the future. The option_name field is a VARCHAR(64), so there’s plenty of room for creativity in option naming. Also, there are not really any tangible restrictions on what characters can be used, though most of us tend to stick with identifers that would be legal variable names when programming.

My suggestion for a format is: area:plugin-slug:option-name
Where area is one of core, plugin, or theme (any others that should be separate?). The plugin-slug is the same as the slug used in the Plugin Repository or Theme Repository. For core options, the slug can be ‘_wp_’ for normal options or ‘_trans_’ for transient options, or they might even be broken down in to sub-areas (‘general’, ‘writing’, ‘discussion’, etc.). For backwards compatibility as names are changed to the new format, core options could go through a deprecation phase where they keep the old names, but the get_option functions could be modified to check for the new names first, then fall back to the old.

Using Twitter Tools as an example again, the aktt_last_tweet_download option could be named plugin:twitter-tools:last_tweet_download. The core option rss_excerpt_length would become core:_wp_:rss_excerpt_length.

Advantages:

  • Finding and deleting options based on their source would become easy. Need to get rid of some leftover options related to the Shazbot theme that you deleted? DELETE FROM $wp->options WHERE option_name LIKE "theme:shazbot:%"
  • New standard option areas and slugs can easily be added in the future while retaining organization.
  • Less chance of namespace collisions between various plugins and themes.

Disadvantages:

  • Added complexity. Coders need to remember to use the new naming scheme, use new option get/set functions which take extra namespacing parameters, or we need to migrate to some sort of universal OOP plugin/theme frameworks in order to enforce consistency.
  • Plugins with longer names get less flexibility with the actual option_name. For example ‘plugin:all-in-one-seo-pack:’ has already eaten up 27 characters which leaves 37 characters for the specific option name. Still not bad, but there might be cases where it could cause problems.
  • Without core buy-in, unlikely to to be utilized by the general plugin/theme codign community.

Other Notes:

Backwards compatibility for core options should be easy, for the most part. I am unaware of any code in the wild using the ‘foo:bar:baz’ format for option names, so collisions with existing plugins is unlikely. The current get_option() function can be modified to match $setting against a regular expression to see if the setting being fetched is namespaced. If so, but the option isn’t found, un-namespace it, and look again. If the setting is not namespaced, and it’s not found, try looking for ‘core:_wp_:$setting’ as a last resort. This behavior could be in place for a few version releases, then deprecated later.

Also, as mentioned on the wp-hackers mailing list, current “best practice” is for a plugin or theme to wrap multiple options up into an array, and save it as a single entry. In some ways, that in itself helps mitigate some of the options table clutter. But a consistent naming standard, if followed by enough developers, would make things even cleaner. And there are certain use-cases where it still makes sense to keep multiple separate options. (I’m guilty of not grouping my options in arrays, but I’m planning to re-vamp all of my plugins eventually)

While I don’t really expect this idea to become part of core, I wanted to put it out in the wild for discussion. At the very least, we might be able to come up with some more solid “best practices” that can be documented on the WordPress Codex.

Further Reading:

You can learn more about how to build options pages for your plugins, and how to deal with options cleanly from these two excellent articles:

Welcome to the new server

After much flailing about and gnashing of teeth, you should now be seeing this site served up by my new webhost. My original plan to use FastCGI + PHP CGI didn’t pan out (for some reason). But with other improvements to my configuration, I think that the new setup should work pretty well.

After it’s had some time to burn in, and I have the chance to twiddle some more knobs, I’ll try to post a few tidbits of what we changed. The real test will be after I make a WordPress-related post and see how it handles a surge of traffic.

Server Reconfig Redux

After a couple of failed attempts at switching to the new server setup, it seems I’m going to have to fall back and punt (at least on a portion of it). With the help of Frederick Townes, I have what should be a really screaming-fast web server setup. But for some reason, it seems that the Apache Worker MPM + FastCGI (mod_fcgid) + PHP CGI combination is not stable. At least, it’s not for me. Both times that I’ve switched DNS and put real traffic on the server, it crashes and burns. It’s like a sports car with a flat tire — it looks great, but it won’t get you very far.

So, I’m going to switch back to pre-fork Apache and mod_php. I’m still splitting MySQL off to its own server, and with Frederick’s help I have some improvements to my Apache config that should greatly improve things. Between those two factors, I expect to have a lot fewer problems, and be able to serve more pageviews during traffic spikes.

With luck, I’ll have more news soon.

New Server

I’ve completed my migration to the new server, as mentioned in my previous post. I’m going to give it a little time for any problems to shake out before I do any heavy testing, but please let me know if you notice anything that doesn’t work correctly.

Update, Dec 2: I’m trying again, after some server configuration help from Frederick Townes (W3 Total Cache author). So far, testing with ApacheBench has looked good.

Server Reconfig

This blog will be moving to a new server very soon. If all goes well, you shouldn’t notice a thing. But just in case, I figured I’d give a warning, so that if you try to visit and you get an error, or the site won’t come up, you’ll know to just come back again later instead of thinking that my site was an early victim of the 2012 apocalypse or something.

I’m doing more than just moving onto a new server though. I’m moving to a new hosting provider, and I’m reconfiguring many aspects of how my services are set up. If you’re interested in the technical nitty-gritty, read on.

Read on to get the technical mumbo-jumbo…

SimpleBits switches to WordPress

Dan Cedarholm, web design guru extraordinaire, has switched his SimpleBits blog to WordPress.

Well, after 6+ years on an ancient and highly customized install of Movable Type 3.15, and 4+ years on various homegrown CMS solutions, I’ve finally upgraded the guts of this site. I chose WordPress. Sure, there are several other excellent options out there to power the blogs of 2010 and beyond, but the familarity of WP, its plugins, pricetag and other factors all fed into the decision. Plus, I told Matt in the halls of SWSW in 2003 that I’d try his little weblog project. I’m finally following through on that.

In addition to running the SimpleBits blog and web design company, Dan is the author of Web Standards Solutions, Bulletproof Web Design, and Handcrafted CSS: More Bulletproof Web Design.

WordPress 2.9 Media Embedding

As promised in my previous post on WordPress 2.9 features, this post will be a demonstration of the super easy media embeds coming in WordPress 2.9. What I find particularly interesting and useful about the new embedding feature, and oEmbed in particular, is that it is truly multimedia. It’s not just about embedding videos. You can embed images, audio, slideshows, or even HTML. Anything that could possibly be included in a web page can be embedded from a remote service via oEmbed.

What’s great about the new media embed feature in WordPress is that it’s so easy to use. How easy? Really easy.
Read on to see media embed examples…

WordCamp Birmingham 2009 Recap

WordCamp Birmingham 2009This post is about two weeks late, but I still wanted to share my notes about WordCamp Birmingham 2009. Short version — it was awesome!

As mentioned previously, I gave a presentation on Jumping into WordPress Plugin Development. When I arrived in Birmingham on Friday night, I still only had a little over half of my presentation notes done, and the rest was still just an outline. I stayed up all night finishing my notes and quickly putting them into a Keynote presentation (which I then exported in several other formats and saved to a USB thumbdrive for safekeeping). I got about two hours of sleep, then I headed over to Innovation Depot.

Read the rest, and see photos…

Jumping into WordPress Plugin Development presentation

Despite an extreme lack of sleep, I managed to make it through my WordCamp Birmingham presentation this morning on Jumping into WordPress Plugin Programming. I didn’t feel as prepared as I wanted to be, but several people gave me some kind comments, so I guess it must have gone okay. Here is the slideshow I used, which I’ve uploaded to SlideShare (where you can also find my presentation from last year).

Obviously, with the slideshow, you don’t get the extra patter and commentary (did anybody record audio?), but the essential pieces are there. When I can find time (heh), I plan to turn this into a series of articles here on my blog, where I will go into much more depth, and give more complex and useful examples.