Signature
$cards = apply_filters( 'mam_nws_get_weather_data', array(), array $locations );
| Parameter | Type | Description |
|---|---|---|
| (seed) | array |
Pass array(); returned unchanged if the plugin is inactive. |
$locations |
array |
Locations in the same shape as mam_nws_weather_for_home_screen_stack: {title, lat, lon, miles?, type?}. |
Returns an array of forecast cards (title, period, temperature, wind, forecast, imageurl, lat, lon, layout fields), distance-sorted when the request carries the user’s location.
What it’s for
This is a service filter — you call it rather than hook it. It runs the locations through the plugin’s table cache (respecting Forecast Cache Duration and Location Match Radius) and only contacts api.weather.gov on cache misses. Because the seed array comes back untouched when mam-nws-weather is inactive, callers degrade gracefully with no class_exists checks.
Example — weather for one venue inside another plugin
$cards = apply_filters( 'mam_nws_get_weather_data', array(), array(
array( 'title' => 'Event Venue', 'lat' => 41.4901, 'lon' => -71.3128 ),
) );
if ( ! empty( $cards ) ) {
$forecast_text = $cards[0]['forecast'];
}
Notes
- Each distinct location/type creates a cached row in
{prefix}mam_nws_weather; reuse coordinates rather than generating many one-off lookups. - US locations only (NWS coverage); failures return no card for that location.
Related articles
- Plugin: mam-nws-weather
- Hook:
mam_nws_weather_for_home_screen_stack
Metadata
| Field | Value |
|---|---|
| Article type | Hook Reference |
| Plugin slug | mam-nws-weather |
| Applies to plugin version | 2.0+ |
| Category | Extending MAM Suite |
| Hook type | filter (callable service) |
| Audience | PHP developer |
| Last verified | 2026-06-12 |
