Skip to content

Instantly share code, notes, and snippets.

@christophercochran
Created December 9, 2014 05:27
Show Gist options
  • Save christophercochran/d9898a5ad7848cb58c3a to your computer and use it in GitHub Desktop.
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.
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