Created
December 9, 2014 05:27
-
-
Save christophercochran/d9898a5ad7848cb58c3a to your computer and use it in GitHub Desktop.
Jetpack Holiday Snow only when it is really snowing. Snow outside your window, snow on your blog.
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
function cc_is_it_snowing() { | |
// Zip Code / City Name | |
$location = 'North Pole'; | |
$weather_data_api_url = 'http://api.openweathermap.org/data/2.5/weather?q=' . $location; | |
$weather_data_response = wp_remote_get( $weather_data_api_url ); | |
if ( is_wp_error( $weather_data_response ) ) { | |
// Errors are no joy. No joy, no snow. | |
return false; | |
} else { | |
$weather_data = json_decode( $weather_data_response['body'], true ); | |
if ( 'Snow' == $weather_data['weather'][0]['main'] ) { | |
// Let it snow. | |
return true; | |
} else { | |
// Elsa doesn't want to build a snowman | |
return false; | |
} | |
} | |
} | |
add_filter( 'jetpack_holiday_chance_of_snow', 'cc_is_it_snowing' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment