Last active
December 12, 2015 07:59
-
-
Save ericmann/4740916 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 . '°'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment