The following witty comment was brought to you by my latest WordPress plugin, Hello Simpsons Chalkboard Gag: Hershey Kisses do not drop from Cupid’s butt.
Everything following the colon above was dynamically pulled from a listing of all past chalkboard gags by Bart Simpson. And no, I did not have to sit through the hundreds of episodes, painstakingly writing down each one. Thanks to The Simpsons Archive, I was able to just write a tiny Perl script that parsed their listing of gags from each episode.
This plugin was inspired by two sources. The first was my love of the over-two-decade-old television show and the second was a desire to show something a little more interesting than lines from Hello Dolly in my WordPress admin area. Let me explain: by default, WordPress comes with a plugin that shows a line from Hello Dolly at the top right corner of every page on the administration side of the site (not visible to general viewers of the site).
As fantastic a musician as Louis Armstrong is, he’s just not my cup of tea. Call me uncultured or say that I’m missing out, but I much prefer Bart’s witty, moderately-crude humor. Also, there are only 28 lines in Hello Dolly, meaning only 28 possible headers in my WordPress admin area. Hello Simpsons Chalkboard Gag has 296 possible results as of publishing this, and that number will continue to grow with each new episode.
In addition to changing up the little bit of text displayed on the admin side of the site, I also added the option to include a simpsons shortcode, which is what was used at the top of this post to load one of the chalkboard gags dynamically within this post. This was really an afterthought and the only reason I decided to include it was because the necessary work was already done in handling the primary project, so adding the shortcode was trivial.
In order to handle the needs of an ever-growing list of possible results for a program that could potentially be installed by thousands of users, I needed to avoid having to change the actual plugin each time a new episode airs. To handle this, I simply setup a Pastebin with all the current gags and hard-coded a link to the page within the plugin source. This way, each time a new gag is released, I just need to add it to the bottom of the list and it will be immediately usable by all versions of the plugin in use.
Beyond that, the plugin was extremely simple. I have initially released in beta since I would like to add some handling to detect if Hello Dolly is in use and, if it is, prompt the user to deactivate it so as to avoid collisions since the similarity in how they are displayed in the admin area will lead to a non-appealing result (though they can function side-by-side if the user really desires it).
Update (Dec. 31, 2012)
This evening the plugin left beta after a major overhaul of the plugin. Other than adding an alert that is displayed to the user on activation if they have a conflicting plugin active, most of the frontend looks exactly the same. This is not the case behind the scenes.
The plugin had been relying on retrieving the most recent chalkboard gags from the remote repository each time the plugin ran (every time any admin page was loaded). To avoid this massive waste of resources, the plugin now relies on a local record of the current chalkboard gags, maintained through the WordPress API using the WP Cron function library, retrieving an updated listing daily. This added functionality allowed me to also explore the WordPress API database access, which I have not previously worked with.