Skip to content

Instantly share code, notes, and snippets.

@ericmann
Last active December 12, 2015 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericmann/4740916 to your computer and use it in GitHub Desktop.
Save ericmann/4740916 to your computer and use it in GitHub Desktop.
<?php
/**
* Outputs the current weather conditions
*/
function ocj_weather() {
$conditions = get_transient( 'current_weather' );
if ( false === $conditions ) {
$key = '771f294942a9ba11';
$current = 'http://api.wunderground.com/api/' . $key . '/conditions/q/OH/Columbus.json';
$response = wp_remote_request( $current );
if ( ! is_wp_error( $response ) ) {
$response = wp_remote_retrieve_body( $response );
$response = json_decode( $response );
$conditions = $response->current_observation;
set_transient( 'current_weather', $conditions, 60 * 60 );
}
}
if ( false !== $conditions ) {
echo '<img class"weather_icon" src="' . $conditions->icon_url . '" /> ' . $conditions->temp_f . '&deg;';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment