#php, #Plugins, #weather, #WordPress

Weather? Here’s Your Weather

So, I got bored one day and decided that I wanted to make a weather widget for WordPress. Sort of. I thought that I needed one for a WordPress theme I was thinking about making. As per my previous experience, I couldn’t quite find one that fit the bill, and some were just downright cumbersome in implementation. A veritable nightmare.

When I first started development, I wasn’t too keen on what API/xml data feeds to use, so I went with the ever popular Weather.com XML data feed. Development was a bear because the terms of use were incredibly restrictive. You had to display their logo, which is fine, but then you HAD to display four links that were meant to generate click-throughs for them in some fashion; and all of this had to be visible near the weather data itself. Ok, I said to myself, I can deal with that, even if it makes the whole thing ugly.

This whole thing is kind of funny to me. But hey, you have to monetize that data.

Two weeks later, they decided to end the free XML data service in favor of a different API model. I thought, “Excellent, I can finally develop something free of the cumbersome links and logos I was required to use before!” Not so fast. This service cost several hundred dollars a year. Not so good for me if I’m creating a plugin. Then I discovered Yahoo! Weather, ironically enough, powered by Weather.com’s data.

Ok, get to it already, jerk.

Fine, fine, fine. I simply thought that background information would be useful for you. With the previous version of this plugin, the version using Weather’s data, you were required to register with Weather.com in order to obtain a key that would allow you to access the data, and I had to build that in to the plugin. This version will work fine without it. Yay! Simplification!

However, your site is limited in the number of requests that can be made in a given day. So if you have a high traffic site you’ll run into issues if you’re constantly requesting data from Yahoo. I had to build in data caching in order to keep those requests down, so now you’ll only access the API once or twice every hour to update data and that should take care of the problem. So, it’s not instant, but probably good enough.

At the moment this plugin is a little hit and miss. I don’t plan on doing much more with it, but feel free to fork this, modify it, whatever.

Download From the WordPress Repository

So, enjoy the fruits of my labor!

4 Responses to “Weather? Here’s Your Weather”

  1. James Clark

    October 13, 2012 @ 9:05 am

    Hi Mike

    Just wanted to say thanks for this plugin, which I’m now using on my site Cathedral City Guide. I had been using another plugin based on the Google weather API but it went screwy so I needed to find a non-Google alternative.

    I’m using your widget in conjunction with the Widget Logic plugin so that the weather displayed is contextual; for example, if you are on a page about York you will see weather for York.

    I especially like the Custom CSS option — I wish all on-page plugins/widgets had this!

    The only bug I have encountered is when swapping between Celsius and Fahrenheit, the unit figure does not update immediately. As a result my site was briefly showing a temperature of 52C for England in October! What a scorcher! Not a major issue though.

    Thanks again for a great plugin


    • Mike

      October 13, 2012 @ 10:15 am

      I’m glad to hear it’s working out for the most part for you. This particular plugin has proved to be quite a bit more complex in some ways then I expected it to be, so bugs like the one you mentioned tend to crop up from time to time. The reason this happens is because the raw data is being cached for about an hour at a time. This way you’re not querying the data source every time someone visits your site; I had to set it up this way in order to respect the query limits they set in place.

      Thank you again!


      • James Clark

        June 25, 2013 @ 1:50 pm

        Hi Mike,

        Sorry, me again. Your plugin is throwing up the following error and I wondered if you could shed any light on it?

        Warning: Invalid argument supplied for foreach() in /home/cathedra/public_html/wp-content/plugins/current-weather/includes/class.wp_current_weather.php on line 186

        I know you aren’t actively working on this plugin any more, but any help you can give would be much appreciated… it would be a blow to have to move to another (inferior) weather plugin!


      • Mike

        June 25, 2013 @ 10:33 pm

        Hey James, to be honest, I’m not sure what you’ve got going on. My development environments appear to be functioning perfectly.

        That line in particular is parsing data from Yahoo! Weather’s XML feed, so unless something has changed in their formatting, there shouldn’t be any problem.

        The only other thing I can think of is that the XML file isn’t being accessed properly due to some server security settings. I would probably lean towards this as an explanation.

Leave a Reply