Available Filters

Filters allow you to change the way my plugin works without having to modify the plugin files directly. This means when updates come out, your changes will not get overwritten. For more information about filters and how they work, see this tutorial by Tom McFarlin. The basic usage involves you placing a new PHP function in your theme. The default placement is the functions.php file of your theme (some themes may have a specific file for them). Here is each available filter with an explanation and code snippit.

Filter Default Value
awesome_weather_cache 1800
awesome_weather_error Error Message
awesome_weather_sizes Simple array of text sizes
awesome_weather_extended_forecast_text extended forecast
awesome_weather_background_classes Array of Background Classes
awesome_weather_wind_speed $val
awesome_weather_wind_speed_text $val
awesome_weather_wind_direction $val
awesome_weather_use_google_font true
awesome_weather_google_font_queue_name opensans-googlefont
awesome_weather_bg_ext jpg
awesome_weather_days_of_week Array of Day Abbrieviations
awesome_weather_extended_url_target _blank
awesome_weather_available_locales Array of Locales
awesome_weather_ip_cache 15552000
awesome_weather_location_lookup_url http://ipinfo.io/[[IP]]/json
awesome_weather_ip_ping_data Array of data (see example)
awesome_weather_trigger_image AWESOME_WEATHER_PLUGIN_BASE . "img/locate.png"
awesome_weather_loader wi-day-sunny
awesome_weather_show_bubble true
awesome_weather_data Empty Array
awesome_weather_result_auto_units_cache 31104000
awesome_weather_codes Array of Weather Translations
awesome_weather_use_custom_translation false
awesome_weather_skip_geolocate false
awesome_weather_custom_template_location false
awesome_weather_background_images_location false

Default: 1800

Determines how many seconds to cache the weather data.

function hg_awesome_weather_cache()
  return 3600; // IN SECONDS
add_filter('awesome_weather_cache', 'hg_awesome_weather_cache');

Default: Error Message

Allows you to change the output of the error message. Most likely to wrap it with your own class.

function hg_awesome_weather_error( $msg )
  return "<div class='my-error-class'>{$msg}</div>";

Default: Simple array of text sizes

A default set of image sizes are available. However, if you build custom templates and want your users to be able to select them, you could add them to the dropdown list.

function hg_awesome_weather_sizes()
 return array( 'wide' => 'Wide', 'tall' => 'Tall', 'custom-name', 'Custom Template Name');
add_filter('awesome_weather_sizes', 'hg_awesome_weather_sizes');

Default: extended forecast

Change the text of the extended forecast link. This can also be changed with the shortcode attribute: extended_text=”See the extended forecast”

function hg_awesome_weather_extended_forecast_text()
  return "See the Extended Forecast";
add_filter('awesome_weather_extended_forecast_text', 'hg_awesome_weather_extended_forecast_text');

Default: Array of Background Classes

This gives you one last chance to add background classes before they are added to the template.

function hg_awesome_weather_background_classes( $classes )
  $classes[] = "theme-awesome";
  return $classes;
add_filter('awesome_weather_background_classes', 'hg_awesome_weather_background_classes');

Default: $val

For a brief stint the wind speed what being weird. This filter allowed you to modify it. It’s most likely not needed but still available. Dive into the code if you need to use it.

Default: $val

For a brief stint the wind information was being weird. This filter allowed you to modify it. It’s most likely not needed but still available. Dive into the code if you need to use it.

Default: $val

For a brief stint the wind information was being weird. This filter allowed you to modify it. It’s most likely not needed but still available. Dive into the code if you need to use it.

Default: true

If your theme uses the Google font Open Sans or you want your widget to match the font of your site, it would make sense for page speed purposes to not call this font. Set it to false to get rid of it.

function hg_awesome_weather_use_google_font()
  return false;
add_filter('awesome_weather_use_google_font', 'hg_awesome_weather_use_google_font');

Default: opensans-googlefont

Enqueueing fonts is how this whole thing works. Here you can change the queue name to match your other Open Sans font. It might make more sense just to use the hg_awesome_weather_use_google_font filter, but this is here for that moment you need it.

function hg_awesome_weather_google_font_queue_name()
  return "open-sans";
add_filter('awesome_weather_google_font_queue_name', 'hg_awesome_weather_google_font_queue_name');

Default: jpg

This filter allows you to change the preset background image file extension to look for. By default it will look for .jpg but you can change it to .png or .gif perhaps even .webm one day.

function hg_awesome_weather_bg_ext()
  return "png";
add_filter('awesome_weather_bg_ext', 'hg_awesome_weather_bg_ext');

Default: Array of Day Abbrieviations

Perhaps you want to change the days of the week to something custom without having to change the translation files. This is where you would do that.

function hg_awesome_weather_days_of_week( $days )
  $days[0] = "Sun.";  
  $days[1] = "Mond.";
  // ETC
  return $days;
add_filter('awesome_weather_days_of_week', 'hg_awesome_weather_days_of_week');

function awesome_weather_spanish_days_of_week()
	return array('Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa');
add_filter('awesome_weather_days_of_week', 'awesome_weather_spanish_days_of_week');

Default: _blank

The extended forecast link opens in a new window. You can blank this out to make it stop.

function hg_awesome_weather_extended_url_target( )
  return "";
add_filter('awesome_weather_extended_url_target', 'hg_awesome_weather_extended_url_target');

Default: Array of Locales

When OpenWeatherMap adds new locale translations you don’t need to wait for the next update to get access to them.

function hg_awesome_weather_available_locales($locales)
	$locales[] = "sk";
	return $locales;

Default: 15552000

How many seconds to cache ip location. I cache the location returned for an IP in transient cache so we don’t have to ping remote servers all the time.

function hg_awesome_weather_ip_cache()
	return 3600; // IN SECONDS
add_filter('awesome_weather_ip_cache', 'hg_awesome_weather_ip_cache');

Default: http://ipinfo.io/[[IP]]/json

URL to ping in order to translate the user’s IP into a location. Works in relationship with with awesome_weather_ip_ping_data

function hg_awesome_weather_location_lookup_url()
  return "http://yourgeolookupservice.com";
add_filter('awesome_weather_location_lookup_url', 'hg_awesome_weather_location_lookup_url');

Default: Array of data (see example)

In the pro plugin we ping the ipinfo.io service to find the City, State for a given IP. You can change this URL to ping a different service. If you do change the url you’ll most likely need to filter with awesome_weather_ip_ping_data the data that is returned to work with my plugin. In the data filter you’ll need to return an array with an attribute of either loc with a long,lat or region with city,state or just city.

function hg_awesome_weather_ip_ping_data( $data_from_new_provider )
  $rtn = new stdclass;
  $rtn->loc       = $data_from_new_provider->longitude . "," . $data_from_new_provider->latitude;
  $rtn->region    = $data_from_new_provider->city . "," . $data_from_new_provider->state;
  $rtn->city      = $data_from_new_provider->city;

  return $rtn;
add_filter('awesome_weather_ip_ping_data', 'hg_awesome_weather_ip_ping_data');

Default: AWESOME_WEATHER_PLUGIN_BASE . "img/locate.png"

There is a button that can allow the user to set their own location. You can use this to customize the button image used. You can also create a whole new template by create an awesome-weather-trigger.php file in your theme folder.

function hg_awesome_weather_trigger_image()
  return "https://urltoyourimage.png";
add_filter('awesome_weather_trigger_image', 'hg_awesome_weather_trigger_image');

Default: wi-day-sunny

When I users tries to set their location a spinning icon appears to let the user know something is happening. By default it is a spinning sun. You can change this to any one of the other icons available for the icon set. Make sure to have the wi- included.

function hg_awesome_weather_loader()
  return "wi-refresh";
add_filter('awesome_weather_loader', 'hg_awesome_weather_loader');

Default: true

On your users first visit and if we cannot locate them properly through their IP, I little bubble pops up letting the user know they can set their own location. This allows you to turn of this functionality.

function hg_awesome_weather_show_bubble()
  return false;
add_filter('awesome_weather_show_bubble', 'hg_awesome_weather_show_bubble');

Default: Empty Array

This allows you to customize any parameters before we attempt to get the weather data from OpenWeatherMap. There is a parameter that passes in the $weather object at it’s current state. Example $weather object just for reference.

function hg_awesome_weather_data( $weather )
  $weather->owm_city_id = 123456;
  $weather->show_icons = 1;
  // etc
  return $weather;
add_filter('awesome_weather_data', 'hg_awesome_weather_data', 10,2);

Default: 31104000

If you set the units to ‘auto’ when ‘Use User Location’ is enabled, the plugin will cache these results to speed your site up. You can customize how long this should stay in your transient database.

function hg_awesome_weather_result_auto_units_cache( $days )
  return 86400;
add_filter('awesome_weather_result_auto_units_cache', 'hg_awesome_weather_result_auto_units_cache');

Default: Array of Weather Translations

If you wanted to do some crazy weather description mapping. You can modify this array.

function hg_awesome_weather_codes( $text )
  $text['tornado'] = "ALERT: Tornado";
  return $text;
add_filter('awesome_weather_codes', 'hg_awesome_weather_codes');

Default: false

OpenWeatherMap templates will pull the weather descriptions from the API (this is the default behavior in the FREE version) instead of from my custom description mapping in the .pot file. You can stop this with this filter and then translate the descriptions as needed.

function hg_awesome_weather_use_custom_translation()
	return true;

Default: false

Allows to you modify the value of skip_geolocate at the last possible second.

function hg_awesome_weather_skip_geolocate()
	return true;

Default: false

Allows you to set a custom template location folder. By default custom templates are looked for in the Child Theme then the Theme. This filter allows you to load them from a different location that won’t get overridden, like a custom plugin in the example below.

function hg_awesome_weather_custom_template_location()
	return dirname(__FILE__);
add_filter( 'awesome_weather_custom_template_location' , 'hg_awesome_weather_custom_template_location' );

Default: false

This filter allows you to set a location folder for background images outside of the theme folder. It requires an object to be returned with a directory for PHP to search for and then a URI for the display. Here is a sample plugin to use, download it. Install it like you would a normal plugin and then load your custom images into the awe-backgrounds folder inside of the plugin.

function hg_awesome_weather_background_images_location()
	$location = new stdclass;
	$location->dir = dirname(__FILE__) . '/awe-backgrounds/';
	$location->uri = '/wp-content/plugins/awesome-weather-bgs/awe-backgrounds/';
	return $location;
add_filter( 'awesome_weather_background_images_location' , 'hg_awesome_weather_background_images_location' );


You can override the basic translations of the plugin with a simple filter.

function hg_awesome_weather_basic_translations( $translations, $widget_id = false )
	$translations->humidity 		= 'humidity';
	$translations->high 			= 'H';
	$translations->low 			= 'L';
	$translations->now 			= 'Now';
	$translations->wind 			= 'wind:';
	$translations->weather_from 		= 'Weather from';
	$translations->set_location 		= 'Set Your Location';
	$translations->search_placeholder 	= 'Search: City, State or Country';
	$translations->city_not_found 		= 'City not found, please try again.';
	return $translations;
add_filter('awesome_weather_basic_translations', 'hg_awesome_weather_basic_translations', 10, 2);