My plugin has provided several functions that are helpful when making your own custom templates or just grabbing weather data to show in various spots around your website. In version
1.1.9 these functions were improved and some new ones were added. These functions utilize your WordPress transient caching system so they should improve performance once the data has been cached. Here is a breakdown of the functions available to you. You can click the function name to learn more and get a code snippet.
Quickly show a weather widget with this nice handy ACF style function. You can pass in one variable as a string, array or object.
// STRING the_awesome_weather_widget('Edmond, OK'); // ARRAY the_awesome_weather_widget( array('location' => 'Edmond, OK', 'size' => 'material' ) ); // OBJECT $settings = new stdclass; $settings->location = "Edmond, OK"; $settings->size = "material"; the_awesome_weather_widget( $settings );
Same data and function as the_awesome_weather_widget only instead of echoing the widget it returns the widget.
// STRING echo get_awesome_weather_widget('Edmond, OK'); // ARRAY $widget = get_awesome_weather_widget( array('location' => 'Edmond, OK', 'size' => 'material' ) ); echo $widget; // OBJECT $settings = new stdclass; $settings->location = "Edmond, OK"; $settings->size = "material"; $weather = get_awesome_weather_widget( $settings );
Grab just the weather data from OpenWeatherMap City ID. It accepts a string, integer (OPENWEATHERMAP CITY ID), array or object. Help guide on how to find your city id.
// STRING $weather = get_awesome_weather_openweathermaps( 'London' ); // INTEGER $weather = get_awesome_weather_openweathermaps( 2643743 ); // OBJECT $where = new stdclass; $where->location = "London, UK"; $weather = get_awesome_weather_openweathermaps( $where ); // ARRAY (Multiple Locations) $locals = get_awesome_weather_openweathermaps( array( 2643743, 'Paris', 'Madrid') );
Grab a weather widget based on a Latitude and Longitude location.
$widget = awesome_weather_widget_by_latlong_openweathermaps(48.856614,2.352222,'material');
Grab the weather data for a Latitude and Longitude location.
$weather_data = awesome_weather_by_latlong_openweathermaps(48.856614,2.352222);
Get a text string of current weather conditions. Here is a list of the available options. If nothing can be found it will return default.
$weather = get_awesome_weather_openweathermaps( 'London' ); // CURRENT CONDITION STRING: sunny, cloudy, snow, etc. echo awesome_weather_preset_condition_names_openweathermaps($weather->data['current']['condition_code']);
If for whatever you reason you want to get the OpenWeatherMap APP ID that you (or your client) has entered to make a custom call to their API. You can grab it with this function. It is smart enough to check for the wp-config first then the option saved in the database.
// GET KEY $appkey = awe_get_appid(); // ... MAKE CUSTOM CALL TO OPENWEATHERMAP $weather = wp_remote_get( "http://api.openweathermap.org/data/2.5/weather?id=345345&lang=sp&units=metric&APPID=" . $appkey);
Get the City ID (for whichever provider) based on a Latitude and Longitude location. The first $weather attribute needs to be an object. And the $what_to_get has two options: just the id or a little object about the location (which includes the id, but also has a city, state, etc.)
// CREATE AN OBJECT $location = new stdclass; $location->longlat_location = '48.856614,2.352222'; // GET CITY ID $city_id = awe_get_long_lat_city_id($location); // GET OBJECT ABOUT CITY $city_data = awe_get_long_lat_city_id($location, 'data');
If you want to convert a temperature from celsius to fahrenheit.
$current_temp = awe_c_to_f( $weather->data['current']['temp'] );