You should ask an AI app to review the weather widget for issues. I asked the following question in Cursor AI:
Are the units used correctly? When I check the data returned from the API call, it doesn’t match up with the data on https://openweathermap.org/ for the same city.
I received the following response:
I’m going to verify the unit handling logic in your weather class against OpenWeather response fields so we can isolate exactly why values differ.
—
Short answer: not fully — there are two real unit bugs in this file.
What’s wrong
w_units handling is incorrect
Any non-empty w_units value is treated as imperial:
td_weather.php
Lines 41-48
$current_unit = 0; // 0 – metric
$current_temp_label = ‘C’;
$current_speed_label = ‘kmh’;
if (!empty($atts[‘w_units’])) {
$current_unit = 1; // imperial
$current_temp_label = ‘F’;
$current_speed_label = ‘mph’;
}
So w_units=”metric” still flips to imperial.
That explains mismatch immediately.
Metric wind label/value mismatch
API requests units=metric, where wind speed is m/s, but code labels it as kmh without converting:
td_weather.php
Lines 428-431
if (isset($api_response[‘wind’][‘speed’])) {
$weather_data[‘today_wind_speed’][0] = round($api_response[‘wind’][‘speed’], 1);
$weather_data[‘today_wind_speed’][1] = self::kmph_to_mph($api_response[‘wind’][‘speed’]);
}
today_wind_speed[0] is m/s, not kmh.
today_wind_speed[1] also assumes km/h input, but input is m/s.
Where to fix
In wp-content/plugins/td-composer/legacy/common/wp_booster/td_weather.php:
Fix unit selection around the if (!empty($atts[‘w_units’])) block.
Fix wind conversions in owm_get_today_data() around wind speed assignment.
—
Then I asked the following:
Can you show me the exact fixes I need to make in order to correct this issue?
—
Yes — make these exact edits in wp-content/plugins/td-composer/legacy/common/wp_booster/td_weather.php.
1) Fix w_units detection (currently always imperial when non-empty)
Replace this block:
$current_unit = 0; // 0 – metric
$current_temp_label = ‘C’;
$current_speed_label = ‘kmh’;
if (!empty($atts[‘w_units’])) {
$current_unit = 1; // imperial
$current_temp_label = ‘F’;
$current_speed_label = ‘mph’;
}
with:
$current_unit = 0; // 0 – metric
$current_temp_label = ‘C’;
$current_speed_label = ‘m/s’;
if (!empty($atts[‘w_units’]) && strtolower($atts[‘w_units’]) === ‘imperial’) {
$current_unit = 1; // imperial
$current_temp_label = ‘F’;
$current_speed_label = ‘mph’;
}
2) Fix wind speed conversion (OpenWeather metric wind is m/s, not kmh)
In owm_get_today_data(), replace:
if (isset($api_response[‘wind’][‘speed’])) {
$weather_data[‘today_wind_speed’][0] = round($api_response[‘wind’][‘speed’], 1);
$weather_data[‘today_wind_speed’][1] = self::kmph_to_mph($api_response[‘wind’][‘speed’]);
}
with:
if (isset($api_response[‘wind’][‘speed’])) {
$weather_data[‘today_wind_speed’][0] = round($api_response[‘wind’][‘speed’], 1); // m/s from api
$weather_data[‘today_wind_speed’][1] = self::mps_to_mph($api_response[‘wind’][‘speed’]); // imperial
}
3) Add proper conversion helper (m/s -> mph)
Replace this function:
private static function kmph_to_mph($kmph)
{
return round($kmph * 0.621371192, 1);
}
with:
private static function mps_to_mph($mps)
{
return round($mps * 2.2369362921, 1);
}
Why this fixes your mismatch
w_units=”metric” will now stay metric (instead of being treated as imperial).
Wind values/labels now match OpenWeather metric/imperial behavior.
If you want, I can apply these edits directly for you now.
—
I followed those instructions and now the weather widget is displaying more realistic data to me.