Available Filters

Use these easy filters to make changes to your widget

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 For Plugin
awesome_weather_cache 1800 BOTH
awesome_weather_error Error Message BOTH
awesome_weather_sizes Simple array of text sizes BOTH
awesome_weather_extended_forecast_text extended forecast BOTH
awesome_weather_background_classes Array of Background Classes BOTH
awesome_weather_wind_speed FREE: array( 'text' => $val, 'speed' => $val, 'direction' => $val ) - PRO: $val BOTH
awesome_weather_wind_speed_text $val BOTH
awesome_weather_wind_direction $val BOTH
awesome_weather_use_google_font true BOTH
awesome_weather_google_font_queue_name opensans-googlefont BOTH
awesome_weather_bg_ext jpg BOTH
awesome_weather_days_of_week Array of Day Abbrieviations BOTH
awesome_weather_extended_url_target _blank BOTH
awesome_weather_available_locales Array of Locales BOTH
awesome_weather_ip_cache 15552000 PRO
awesome_weather_location_lookup_url http://ipinfo.io/[[IP]]/json PRO
awesome_weather_ip_ping_data Array of data (see example) PRO
awesome_weather_trigger_image AWESOME_WEATHER_PLUGIN_BASE . "img/locate.png" PRO
awesome_weather_loader wi-day-sunny PRO
awesome_weather_show_bubble true PRO
awesome_weather_data Empty Array PRO
awesome_weather_result_auto_units_cache 31104000 PRO
awesome_weather_codes Array of Weather Translations PRO
awesome_weather_use_custom_translation false PRO
awesome_weather_appid APP ID submitted in Settings -> Awesome Weather FREE
awesome_weather_units_display ° FREE

awesome_weather_cache
Default: 1800
Plugin: Both

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');

awesome_weather_error
Default: Error Message
Plugin: Both

Allows you to change the output of the error message. Most likely to wrap it with your own class. Error functionality was updated in FREE version 1.5.3 to match the error handling of the PRO plugin. New options allow you to only show the errors for admin users.

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

awesome_weather_sizes
Default: Simple array of text sizes
Plugin: Both

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');

awesome_weather_extended_forecast_text
Default: extended forecast
Plugin: Both

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');

awesome_weather_background_classes
Default: Array of Background Classes
Plugin: Both

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

function hg_awesome_weather_background_classes( $classes )
{
  // CAN DO WHATEVER HERE:
  unset($classes['darken']);
  $classes[] = "theme-awesome";
  return $classes;
}
add_filter('awesome_weather_background_classes', 'hg_awesome_weather_background_classes');

awesome_weather_wind_speed
Default: FREE: array( 'text' => $val, 'speed' => $val, 'direction' => $val ) - PRO: $val
Plugin: Both

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.

awesome_weather_wind_speed_text
Default: $val
Plugin: Both

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.

awesome_weather_wind_direction
Default: $val
Plugin: Both

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.

awesome_weather_use_google_font
Default: true
Plugin: Both

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');

awesome_weather_google_font_queue_name
Default: opensans-googlefont
Plugin: Both

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');

awesome_weather_bg_ext
Default: jpg
Plugin: Both

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');

awesome_weather_days_of_week
Default: Array of Day Abbrieviations
Plugin: Both

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');

awesome_weather_extended_url_target
Default: _blank
Plugin: Both

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');

awesome_weather_available_locales
Default: Array of Locales
Plugin: Both

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;
}
add_filter('awesome_weather_available_locales','hg_awesome_weather_available_locales');

awesome_weather_ip_cache
Default: 15552000
Plugin: Pro

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');

awesome_weather_location_lookup_url
Default: http://ipinfo.io/[[IP]]/json
Plugin: Pro

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');

awesome_weather_ip_ping_data
Default: Array of data (see example)
Plugin: Pro

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;
  
  // 3 OPTIONS AVAILABLE FOR RETURN DATA
  $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');

awesome_weather_trigger_image
Default: AWESOME_WEATHER_PLUGIN_BASE . "img/locate.png"
Plugin: Pro

The PRO version has 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');

awesome_weather_loader
Default: wi-day-sunny
Plugin: Pro

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');

awesome_weather_show_bubble
Default: true
Plugin: Pro

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');

awesome_weather_data
Default: Empty Array
Plugin: Pro

This allows you to customize any parameters before we attempt to get the weather data from either Yahoo or 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);

awesome_weather_result_auto_units_cache
Default: 31104000
Plugin: Pro

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');

awesome_weather_codes
Default: Array of Weather Translations
Plugin: Pro

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');

awesome_weather_use_custom_translation
Default: false
Plugin: Pro

As of PRO version 1.1.5, 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;
}
add_filter('awesome_weather_use_custom_translation','hg_awesome_weather_use_custom_translation');

awesome_weather_appid
Default: APP ID submitted in Settings -> Awesome Weather
Plugin: Free

This filter is still lingering around in the FREE version of the plugin. It allows you to globally set the APP ID with a filter. There is also a constant that can be set in wp-config.php called AWESOME_WEATHER_APPID to achive the same results.

function hg_awesome_weather_appid()
{
  return "YOUR APP ID HERE";
}
add_filter('awesome_weather_appid', 'hg_awesome_weather_appid');

awesome_weather_units_display
Default: °
Plugin: Free

Ability to change the little degree to whatever you need. PRO users can create custom templates.

function hg_awesome_weather_units_display()
{
  return "F";
}
add_filter('awesome_weather_units_display', 'hg_awesome_weather_units_display');