www.openweathermap.org"; } // ================ Callback Fields ================ public function api_key_callback($arguments) { // This is, where the input field for the api key goes echo ''; printf( ' %s', $this->api_helper ); $api_additional_help = __('Get your API-Key on', 'aiws-weather')." www.openweathermap.org"; printf( '

%s

', $api_additional_help ); } public function units_callback($arguments) { // Fetch existing option: $checked = get_option('aiws_units'); $checked_imperial = ''; $checked_metric = ''; if($checked == 'imperial') { $checked_imperial = "checked"; } if($checked == 'metric') { $checked_metric = "checked"; } // This is, where the input field for the unit goes echo '   '; } public function aiws_display_temperature_symbol_callback($arguments) { // Fetch existing option: $checked = get_option('aiws_display_temperature_symbol'); $checked_yes = ''; $checked_no = ''; if($checked == 'yes') { $checked_yes = "checked"; } if($checked == 'no') { $checked_no = "checked"; } // Radio buttons if you want to display symbols or not echo '   '; } public function aiws_default_city_callback($arguments) { // This is, where the input field for the default city goes echo ''; $additional_help_aiws_default_city = __('This city is used, if you omit the optional parameter "citycode" in your shortcode. Useful for repeating weather data of one specific city throughout the blog.', 'aiws-weather'); printf( ' %s', $this->aiws_default_city_helper ); printf( '

%s

', $additional_help_aiws_default_city ); } // ================ Create the settings page ========= // This is, where all the content is put together and the API-Key is checked public function plugin_settings_page_content() { ?>

Inline Weather Shortcodes

api_helper = ''.__('No API-Key set.', 'aiws-weather').""; } else { // Now try to fetch weather data from London (id=2643743) // First try connection $citycode = get_option('aiws_default_city'); $weather_request_string = "http://api.openweathermap.org/data/2.5/weather?id=" . $citycode . "&APPID=" . $api_key; $weather_request = wp_remote_get($weather_request_string); if(is_wp_error($weather_request)) // Does the request return an error-object? { $this->api_helper = ''.__('Error trying to connect to the server.','aiws-weather').""; } else { // The connection seems to be fine // Second try fetching data from json $weather_data = json_decode($weather_request['body']); // If default city wasn't found if( isset($weather_data->cod) AND $weather_data->cod == 404) { $this->api_helper = ''.__('This API-Key is valid.', 'aiws-weather').""; if(isset($citycode) && $citycode != '') { $this->aiws_default_city_helper = ''.__('City not found.', 'aiws-weather').''; } } // If the API-Key is wrong elseif( isset($weather_data->cod) AND $weather_data->cod == 401) { $this->api_helper = ''.__('This API-Key is not valid.', 'aiws-weather').""; } // If the status code is allright (cod == 200) elseif( isset($weather_data->cod) AND $weather_data->cod == 200) { $this->api_helper = ''.__('This API-Key is valid.', 'aiws-weather').""; $this->aiws_default_city_helper = ''. $weather_data->name .", ". $weather_data->sys->country .''; } // If there is another error else { $this->api_helper = __('Unknown error.', 'aiws-weather'); } } } // After validating API-Key print the fields and submit button settings_fields('aiws_weather'); do_settings_sections('aiws_weather'); submit_button(); ?>

www.openweathermap.org

www.openweathermap.org and search for your city. Open the site and have a look at the URL, for example:
http://openweathermap.org/city/2857458. The number at the end of the URL is the citycode.', 'aiws-weather'); ?>

www.openweathermap.org.

[temp] wherever you want to display the current temperature of your default city. Thats all!','aiws-weather'); ?>

[temp citycode="xxxxxxx"] wherever you want, to get the temperature from the city you want.','aiws-weather'); ?>

[tempDay day="x" citycode="xxxxxxx"] shortcode. Both parameters are optional, if you omit day="x", the shortcode will return temperature of the current day. Possible values are 0 - 5.','aiws-weather'); ?>

citycode="xxxxxxx" the default citycode is used.', 'aiws-weather'); ?>