Countdown Timer v3.0.6

Sometime in June of 2012 I released version 3.0 of Countdown Timer. Before that, the last major release was version 2.4 in April of 2010.

I’ve just been busy with other things1. The other reason was that the program had grown from it’s modest roots as a single 321 sloc2 program to a multiple files (80% PHP / 20% JS) with 1,450 sloc. Managing all the files, testing, and integration is — well — hard and not fun. And no one pays me to do it.

It’s taken some time, but I’ve more or less completely redesigned how I develop PHP. I’ve switched to using Aptana, Git Hub, and FirePHP — a PHP integration into FireBug. This was a multimonth project to slowly learn a new way of developing, but it’s been fun! I just spent most of May 2012 essentially rewriting how Countdown Timer works. All the logic is ultimately the same, much of it was converting function and variables into appropriate classes. I’m somewhat particularly happy about being able to extend the DateTime class and use that, although the lastest bug fix release (v3.0.6) was released because of my new found hatred for the DateTime class.

Another big change from 2.4 was taking advantage of some of WordPress’ core i18n3 updates which make handling date and time information a bit easier. Version 3 (and the subsequent dot fix updates) haven’t been a big flashy update, things are more or less where you left them, but you should hopefully see some little things that make you smile and make your life easier. It’s always a challenge to keep making something truly better, but I still have a couple of things I want to implement. However, Countdown Timer is on GitHub and WordPress TRAC, I don’t want this to be code that’s hidden in a cave, so please fork, patch, push and pull away.

Anyway, version 3.0.6 is now out. It fixes some crazy bug with that developed sometime after PHP 5.2 was released that caused the “white screen of death.” There were three issues that I found:

  • WordPress is calling the sanitize callback twice…not sure if this is new behavior or not, but it was breaking things because the second time it was being called it was trying to sanitize a different type of input. I’ll probably need to rewrite the sanitize function in the future.
  • The DateTime class has been expanded and some of the new functions clashed with stuff I had written. PHP can’t overload functions, so instead it just barfs.
  • For some reason, if certain, presumably optional, methods of the new PHP DateTime class are missing, PHP will also barf. In particular, date4, timezone_type5, and timezone.

Anyway, several hours were spent backtracing the errors and providing suitable fixes. So, enjoy!

As per tradition:

Read more or download version 3.0.6!

Also, please consider that I spend several dozens hours making updates for each release…have you donated recently?


  1. which is to say that Countdown Timer has been pushed lower down my priority list 

  2. source lines of code 

  3. internationalization 

  4. which was never supposed to be exposed 

  5. also maybe a bug? 

Countdown Timer v2.4

Just over a year ago I released Countdown Timer v2.3.5. I’ve had the fortunate opportunity to participate many great things over the last year, which is probably why there hasn’t been an release since.

Anyway, I’ve been slaving away at this release for the last three weeks:

Weeks of 2010 - Blue = Internet Applications (i.e. Chrome, Firefox, IE); Red = Development Applications (i.e. Dreamweaver); Tan = Utilities (i.e. PuTTY, FileZilla, etc)
Weeks of 2010 - Blue = Internet Applications (i.e. Chrome, Firefox, IE); Red = Development Applications (i.e. Dreamweaver); Tan = Utilities (i.e. PuTTY, FileZilla, etc)

I probably spent close to twenty hours, committed over 50 revisions, and had 865 lines changes in the core code1. For all this change behind the scenes, you expect to see some changes in the actual interface. Amazingly not.

Most of the work had to do with bringing the code up to WordPress 2.9/3.0 standards. This will ensure that this plugin continues to work well in to the future. As well as trying to keep up with best practices for WordPress Plugin coding.

The other major update dealt with adding CSS hooks to the html elements so that they can be customized better/more fully. In doing this, I also rewrote part of fergcorp_countdownTimer_format to make it less repetitive. This, unfortunately, caused a minor issue with using the [fergcorp_cdt_single date="ENTER_DATE_HERE"] shortcode that has the li-element included; I’ll fix that in a dot-dot release (i.e. 2.4.1).

The settings for Countdown Timer moved the WordPress Tools to Settings in the Admin Menu and you only need to be an Options Manager instead of Administrator to update the options. I think the only other change worth mentioning is that there is now an option to parse shortcodes in the_excerpt. Note that enabling this functionality will parse all shortcodes, not just ones related to Countdown Timer.

As per tradition:

Read more or download version 2.4!


  1. There’s only 1000 source lines of code [SLOC] to begin with, so this is sort of substantial 

FlickrViewer for AutoViewer

When I was creating the website for my photography endeavor, I wanted a place to show off my photos. I stumbled upon AutoViewer and thought it would be a good method for displaying my photos. However, I wanted the ease of using Flickr’s Slideshow so I could easily update my portfolio.

Mark Sweeting has a PHP script, FlickrViewer, which allows for integration of a Flickr Set with SimpleViewer, the sister program to AutoViewer. Being a programmer, I modified Mark’s script to work with AutoViewer and voila: FlickrViewer for AutoViewer.

There are two major things that I changed. The first was making the XML output compatible with what AutoViewer expects1. The second thing was to add a series of calls to Flickr to get the appropriate image URLs.

This is not an official product offering, so the extend that I’m planning on maintaining this code is the extent that I need to for my own purposes and the extent that someone wants to fund development. Otherwise, have it. Released under the GNU General Public License.

Download: flickrViewer v0.9 for AutoViewer

You’ll also need to download AutoViewer.

You’ll also may need an API key from Flickr if you want to share private photos. It’s free at http://www.flickr.com/services/api/misc.api_keys.html


  1. which, for some reasons, is different than what SimpleViewer expects 

Countdown Timer v2.3.5

Hot off the press, Countdown Timer 2.3.5 is now available for consumption.

This is a small update that resolves a few issues, including:

  • Updated calculation routine to ensure that dates are accurately when “Months” are not displayed.
  • Updated readme.txt file to make some things more clear
  • Fixed small display issue in the administration menu

Also included are six new languages:
Latvian, Romanian, Russian, Danish, Lithuanian, and Serbian.

Read more or download version 2.3.5!

25 Random Things About Me

Rules: Once you’ve been tagged, you are supposed to write a note with 25 random things, facts, habits, or goals about you. At the end, choose 25 people to be tagged. You have to tag the person who tagged you. If I tagged you, it’s because I want to know more about you.

(To do this, go to “notes” under tabs on your profile page, paste these instructions in the body of the note, type your 25 random things, tag 25 people (in the right hand corner of the app) then click publish.)

  1. I’m an introvert.
  2. I want to go into space (and visit the Moon, specifically), but probably won’t get the chance.
  3. I plan on getting my EMT.
  4. I plan on getting my pilots license.
  5. I plan on getting a masters degree (although I don’t know in what).
  6. I plan on getting my professional engineers license.
  7. My blood type is O+
  8. I have a website: http://andrewferguson.net
  9. I’ve been consistently blogging since 2003 (2099 posts and counting).
  10. I listen to NPR podcasts when I go to bed (Wait, Wait…Don’t Tell Me; This American Life; Radio Lab; Car Talk).
  11. My goal is see every single Star Trek TV show and movie, in order, before I graduate college.
  12. So far, I’ve watched 661 Star Trek episodes and movies, I have 116 left.
  13. I enjoy programming, especially in PHP.
  14. I enjoy taking photographs and I want to expand.
  15. I’m thinking about going on a mission trip this summer.
  16. I’ll be working in Seattle for Boeing after I graduate.
  17. Out of all five of the years I’ve been in college, I serously think this year has been my favorite.
  18. I think it’s been my favorite because of the amazing community I found at MERGE and The Annex.
  19. I’m worried about going back to Seattle.
  20. I used to drink rediculous amounts of Dr Pepper. Now I try to limit myself.
  21. I have been diagnosed with generalized anxiety.
  22. I used to have lots of panic attacks in school, all the way into high school. I do pretty well now.
  23. I turn 23 on Saturday.
  24. I share the exact same birthday as my mom…only 30 years later.
  25. I think it’s harder to be a Christian and an American than it is to be a Christian and a scientist. I struggle every day.
  26. I can’t put my contacts in using two hands, I have to do it with one hand. I blame my dad for this.

Note: I’m posting this on my blog, which is then sucked into my Facebook Notes.

Using add_meta_box()

Note: Updated to be compatible with WP2.7.

Note: Technical content to follow.

In the WordPress 2.5 upgrade, Automattic completely revamped the administration interface – including the way that boxes were created for plugins (well, really the entire administration back end; however I will be focusing on plugins). Previously, you had to create the boxes manually, hard coding something to the effect of:

<div class="dbx-b-ox-wrapper">
<fieldset id="myplugin_fieldsetid" class="dbx-box">
<div class="dbx-handle-wrapper"><h3 class="dbx-handle"><?php _e( 'My Post Section Title', 'myplugin_textdomain' ); ?></h3></div>
<div class="dbx-content-wrapper">
<div class="dbx-content">
Your plugin box content here
</div>
</div>
</fieldset>
</div>

Source: http://codex.wordpress.org/Function_Reference/add_meta_box

But how do you get those slick looking boxes seen in WordPress 2.5 and WordPress 2.6 and WordPress 2.7? I looked online and I found plenty of sites detailing how to add meta boxes to the post page. However, I didn’t find anything describing how to implement the add_meta_box() function for your own plugin page.

I spent a bit of time time and reverse engineered the process. Once you have it figured out, it’s really quite simple. At the very least, it’s a lot more intuitive.

First, you’ll want to wrap your content you want to display in a function that echos it out. You’ll need a separate function for every box you want to add. After the function has been declared, you’ll want to add it using the add_meta_box() call. The usage for add_meta_box is:

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

Here’s the PHPDoc data:
string $id String for use in the ‘id’ attribute of tags.
string $title Title of the meta box
string $callback Function that fills the box with the desired content. The function should echo its output.
string $page The type of edit page on which to show the box (post, page, link)
string $context The context within the page where the boxes should show (‘normal’, ‘advanced’)
string $priority The priority within the context where the boxes should show (‘high’, ‘low’)

add_meta_box simply adds the box to a queue. It doesn’t actually spit out any code. Thus, after you’ve created all the content callback functions and added them to the meta box queue with add_meta_box, you’ll need to execute do_meta_boxes().

<?php do_meta_boxes('page', 'context', 'object'); ?>

string $page The edit page which you want to display; this will be the same as $page specified in add_meta_box.
string $context The context within the page where the boxes should show (‘normal’, ‘advanced’).
? $object I don’t know, I just have it set to null.

All together, the code might look something like:

<?php
function yourplugin_helloworld_meta_box(){
?>
Hello, world!
<?php
}
add_meta_box("yourplugin_helloworld", __('Say Hello', 'yourplugin'), "yourplugin_helloworld_meta_box", "yourplugin");
do_meta_boxes('yourplugin','advanced',null);
?>

One weird/interesting thing I discovered is that ‘yourplugin’ can only consist of lowercase letters a-z and the hyphen “-” symbol. For all you programmers, it must return true when matched against /^[a-z-]+$/

I don’t know what, but that’s the check run on line 620 of /wp-admin/admin-ajax.php from WordPress 2.6.2.

That’s the most basic level of creating your own meta boxes. However, there’s more. Do you notice how sometime the meta boxes are closed on the posts (or pages, or links) page? The open/closed position is remembered using some AJAX. The actual data is stored per user in the wp_usermeta table with a meta_key of ‘closedpostboxes_yourplugin’. The data is a serialized array that lists just the closed the boxes.

To get this functionality, you’ll need to perform a couple more steps. First, you’ll need to add some javascript. This code does two things, on load it closes boxes that should be closed (because they were previously closed) and it allows the boxes to be toggled open and closed.

jQuery(document).ready( function($) {
	// close postboxes that should be closed
	jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
		
	// postboxes
	<?php
	global $wp_version;
	if(version_compare($wp_version,"2.7-alpha", "<")){
		echo "add_postbox_toggles('yourpluging');"; //For WP2.6 and below
	}
	else{
		echo "postboxes.add_postbox_toggles('yourplugin');"; //For WP2.7 and above
	}
	?>
			
});

You’ll also need to add this PHP code:

<?php
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
?>

This code registers a new nonce that your plugin will use to send authorized AJAX requests.

And that’s it. Give a holler in the comments if you have questions and I’ll try my best to answer them.

See also: http://xref.fergcorp.com/

Force User Field Registration v0.6

So it seems like WordPress 2.5 ended up breaking some things in the previous version. So I did some work over the weekend and brought everything back up to speed. Here’s a list of what’s been updated:

  • Added PHPDoc
  • Updated add_action to use inbuilt filter rather then have users add their own
  • Update admin UI to 2.5 LnF1
  • Updated input tag to make it look like native input tags
  • Updated fergcorp_forceRegistrationField_updateFields to use passed variable instead of DB query
  • Updated error handling in fergcorp_forceRegistrationField_checkFields to use the new WP_Error object (note: this makes WP 2.5 a minimum requirement)

I think the best news is that you don’t need to modify files anymore to get the plugin to work, you can just drop it in and go. WordPress also has implemented a new error handling framework (WP_Error) which is pretty spiffy.

On a side note, I did take a gander at the MU version of the plugin and it appears to be working properly…at least for now.

Read more or download it!

1 LnF: Look and Feel

Countdown Timer v2.2

I wanted to release this earlier, but between finals, being sick, and field session, I haven’t had a lot of time. This version of Countdown Timer (almost) updates the UI to 2.5 look and feel. As it turns out, there’s actually some function calls I can use to better create the UI and I’ll be using those in the future. There’s a couple of bug updates and added some new functionality.

Also, Countdown Timer v2.2 requires WordPress 2.5 or higher!

The run down:

  • Updated some phrases that missed being i18n.
  • Updated i18n to use use sprintf’s to assist in proper translation.
  • Update the admin page to WordPress 2.5 Look and Feel.
  • Users are now able to define the data (text/HTML) that comes after the title and before the actual countdown.
  • Implemented a new function, fergcorp_countdownTimer_single($date), that allows users to create a one-off event outside of The Loop. $date should be PHP strtotime parseable string.
  • Plugin output is now XHTML 1.0 Strict compliant.

Read more or download version 2.2!

phPo Translator – Online PO Translator

One of the great things about being a programmer is that when I have a problem, it’s pretty easy to solve it myself1.

I recently began to seriously support i18n (internationalization) in the Countdown Timer. It’s actually a pretty slick system. Everywhere I have some text that’s output in the plugin, I wrap it in a WordPress defined function that handles the translation. Then I generate a PO file using poEdit and make a MO (which is just a binary/machine object file of the PO file, which is human readable).

The issue is, if someone wanted to translate the PO file, they’d have to download poEdit, figure out how to use it, grab the PO file, translate it, make the MO file, and then send the MO file to me. This works pretty well if the users is a computer guru. But that’s not often the case.

I was hoping there would be an online PO translator, but I couldn’t find one. So I decided to make my own. Thus I present, in the form of clever titles that mash two words together, phPo Translator (or just phPo for short).

I basically wrote the code over lunch today and then decided that I should version control it. So I threw it up on Google Code, which I knew about but had never, up until this point, actually used.

Google Code is simply amazing. It took less then a minute to register and it uses SVN, which I already have installed on my computer. So I upload the code, create the tag, and away we go!

In any event, you can:

See it in action: Translate afdn_countdownTimer.po
Download phPo Translator v0.1.1
View phPo Translator Google Code page


  1. Granted, most of my problems are probably caused because I am a programmer 

Countdown Timer v2.1.1

After dilly dallying around for a couple months, I finally got serious about pushing the 2.1 version out the door. A couple of reasons for this actually.

First, the WordPress 2.5 is coming out end of March/beginning of April and I wanted to get out one more release (this one) before the next version of WordPress hits the streets.

Second, it’s fits with my development flow; releasing every few months when I can.

Here are the list of updates in Countdown Timer v2.1.1:

  • Fixed i18n translation issues where mo file would sometimes not be loaded
  • Updated UI (note: Based on UI code from Google XML Sitemaps)
  • Removed code dealing with recurring events (which has not been included for a few versions now)
  • Added js countdown ability to admin example (which doesn’t have wp_footer hook?)
  • Updated the link to the JS file to make it dynamic in case a folder gets renamed
  • Fixed a bug in the JS file that caused dates to be calculated incorrectly
  • Append a letter to the beginning of the unique id (as per XHTML requirement)…who knew?
  • Added two language files: Swedish (thanks to Mattias Tengblad) and Spanish (thanks to Google Translator)

The biggest change user will notice is the new UI. It’s based off the code from Google XML Sitemaps which I’m assuming is based off the code from WordPress itself. The great thing about the new design is that you can collapse, expand and move around the boxes to fit your work flow.

All the other changes are ‘under the hood’ and deal with code changes to make things work better in a larger variety of situations.

The Countdown Timer plugin is about three months shy of its third anniversary of public release! I’ve basically been maintaining it since the end of freshman year in college, which is when I switched to WordPress.

The first public version was v0.6. It had about 50 lines of code and used a text file to store the data. There was also no UI at all.

Version 2.1 is about 950 lines of code. Storing data in a text file is gone, instead using the WPDB. There are also several support files, including the javascript port of the countdown mechanism which is another 150 LoC.

Since the beginning of last March, there have been over 8700 downloads, which would almost pay for a semester of college if everyone gave a $1 (wink wink)!

Read more or download version 2.1.1!

Update: Had to increment the plugin to version 2.1.1 because of the way that WordPress does version numbers. In short, v2.01 is the same as v2.1. So I had to release this as 2.1.1.