<?php
/*
Plugin Name: Weather Plugin
Plugin URI: http://www.yourpluginurlhere.com/
Version: Current Version
Author: Name please
Description: What does your plugin do and what features does it offer...
*/
/**
* Weather Plugin For Wordpress
*/
/**
* Proper way to enqueue scripts and styles
*/
define('APFSURL', WP_PLUGIN_URL . "/" . dirname(plugin_basename(__FILE__)));
function theme_name_scripts() {
//define('weather-plugin', WP_PLUGIN_URL . "/" . dirname(plugin_basename(__FILE__)));
wp_enqueue_style( 'weather-plugin', get_stylesheet_uri() );
wp_enqueue_script( 'weather-plugin',APFSURL.'/js/weather-plugin.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
add_shortcode('weather-plugin','weather_function');
function weather_function(){
$ip = '203.135.41.33';//$_SERVER['REMOTE_ADDR'];
$xml = new SimpleXMLElement(file_get_contents("http://www.geoplugin.net/xml.gp?={$ip}"));
$city = (array)$xml->geoplugin_city;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22%27'.$city[0].'%27%2C%20ak%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$weather_rss = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
$return = json_decode($weather_rss);
var_dump($weather_rss);
$temp = $return->query->results->channel->item->condition->temp;
echo "<div>
Weather : ";
echo "<div class = 'farenheit'> ".$temp." </div>";
$centi = 5/9*($temp-32);
$centi1 = number_format((float)$centi, 0, '.', '');
echo "<div class = 'centigrade' style='display:none'> ".$centi1." </div>";
echo "<a hredf='#' id='btn1'> F</a>
/
<a href='#' id='btn2'> C</a>";
echo "</div>";
}
?>
preferences:
57.1 ms | 402 KiB | 5 Q