Country Codes Search & Time Zone Search WordPress Plugin

Whenever I’m given a project, I’m not always certain if it’s possible, but now-a-days, with APIs, everything possible.

The project goal I came up with was “find something that lets a user type in a place and get a country code for that place.”

This task actually started out pretty simple. I just had to copy and paste a giant list of country codes into a page. The client wasn’t very happy with this solution (see project goal).

First, I browsed WordPress plugins to see if someone else did this. This is always the first step. See if someone else has done it. Sadly, no one else had. Step two. Come up with solutions. API was the first thing that came to mind. Google’s API looked promising. Google typically has a pretty good amount of knowledge. Definitely more than me. But this time it wasn’t very helpful.

I think I found a couple APIs, but I settled on the Rest Countries API. This is an amazing API because you don’t need an API key. API keys are a pain.

Step three. Get it to work. Baby steps. I used my new friend Curl to get the data, and I added the data to a table. Tables are always good for this type of stuff.

My fourth step. Let a user take advantage of the code I just created. AJAX. Ajax is always the answer when it comes to little plugins that need user input.

Well, I created the plugin, and it turned out very well.

Country Codes WordPress Plugin Summary

  • I AJAX and PHP to get country codes from an API.
  • I then used jQuery to attach the data to the HTML.

Time Zone Search WordPress Plugin

This plugin was a lot like the plugin above, and it was for the same project, so I included it in this blog post, as well.

  • Google’s Geocoder API and Time Zone API used to convert locations into coordinates and then to time zones.
  • User input sent to server using AJAX and sent to Google’s Geocoder API using PHP. Response data (coordinates) sent to Google’s Time Zone API. Response data from Time Zone API returned to JS and HTML updated with jQuery.