'', 'id' => '', 'background_color' => '', 'background_img' => '', 'width' => '', 'height' => '', 'api_key' => '', 'location' => '', 'units' => '', 'weather_detail' => '', 'forecast' => '', 'forecast_cnt' => 4, ),$args ); extract( $defaults ); self::$args = $defaults; if(is_numeric($width)) $width = $width.'px'; if(is_numeric($height)) $height = $height.'px'; $uniqid = uniqid('weather-'); $class .= ' '.$uniqid; $api_query = ''; if(is_numeric($location)){ $api_query = "id=" . urlencode($location); }else{ $api_query = "q=" . urlencode($location); } $now_ping = "http://api.openweathermap.org/data/2.5/weather?" . $api_query . "&units=" . esc_attr($units) ."&APPID=".esc_attr($api_key); $now_ping_get = wp_remote_get( $now_ping); // PING URL ERROR if( is_wp_error( $now_ping_get ) ) return $now_ping_get->get_error_message(); // GET BODY OF REQUEST $city_data = json_decode( $now_ping_get['body'] ); if( isset($city_data->cod) AND $city_data->cod !== 200){ return $city_data->message; } $data_main = ''; $wi_class = ''; if(isset($city_data->weather)){ $data_main = $city_data->weather[0]->main; $data_icon = $city_data->weather[0]->icon; switch($data_icon){ case '01d': $wi_class = 'wi-day-sunny'; break; case '01n': $wi_class = 'wi-night-clear'; break; case '02d': $wi_class = 'wi-day-cloudy'; break; case '02n': $wi_class = 'wi-night-alt-cloudy'; break; case '03d': $wi_class = 'wi-day-cloudy-gusts'; break; case '03n': $wi_class = 'wi-night-alt-cloudy-gusts'; break; case '04d': $wi_class = 'wi-day-cloudy-windy'; break; case '04n': $wi_class = 'wi-night-alt-cloudy-windy'; break; case '09d': $wi_class = 'wi-day-showers'; break; case '09n': $wi_class = 'wi-night-alt-showers'; break; case '10d': $wi_class = 'wi-day-rain'; break; case '10n': $wi_class = 'wi-night-alt-rain'; break; case '11d': $wi_class = 'wi-day-thunderstorm'; break; case '11n': $wi_class = 'wi-night-alt-thunderstorm'; break; case '13d': $wi_class = 'wi-day-snow'; break; case '13n': $wi_class = 'wi-night-alt-snow'; break; case '50d': $wi_class = 'wi-day-fog'; break; case '50n': $wi_class = 'wi-night-fog'; break; } } $html = ''; $html .= '
'.round($city_data->main->temp).'°C
'; break; case 'imperial': $html .= ''.round($city_data->main->temp).'°F
'; break; } endif; if($weather_detail == 'yes'): $days = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $today = $days[date('w')]; $sunrise = ''; $sunset = ''; $temp_max = ''; $temp_min = ''; $humidity = ''; $pressure = ''; $wind = ''; if(isset($city_data->sys)){ $sunrise = date('H:i',$city_data->sys->sunrise); $sunset = (date('H',$city_data->sys->sunset)-12).':'.date('i',$city_data->sys->sunset); } //current temp $ping_temp = "http://api.openweathermap.org/data/2.5/forecast/daily?".$api_query . "&units=" . esc_attr($units) ."&APPID=".esc_attr($api_key)."&cnt=1"; $temp_ping_get = wp_remote_get($ping_temp); $temp_data = json_decode( $temp_ping_get['body'] ); if(isset($temp_data->list)){ switch($units){ case 'metric': $temp_max = round($temp_data->list[0]->temp->max).'°C'; $temp_min = round($temp_data->list[0]->temp->min).'°C'; break; case 'imperial': $temp_max = round($temp_data->list[0]->temp->max).'°F'; $temp_min = round($temp_data->list[0]->temp->min).'°F'; break; } $humidity = $city_data->main->humidity; $pressure = $city_data->main->pressure.' hpa'; } if(isset($city_data->wind)){ switch($units){ case 'metric': $wind = $city_data->wind->speed.'m/s'; break; case 'imperial': $wind = $city_data->wind->speed.'mph'; break; } } $html .= ''.$today.'
'.$forcastday.' | '.$forcaset_max.' | '.$forcaset_min.' |