[WordPress] problemi plug meteo api key

michele81

Nuovo Utente
2 Dic 2019
4
0
1
Salve ha tutti devo sviluppare un plugin che crei un widget meteo sto usando come servizio di apikey : https://www.wunderground.com/member/api-keys questo è il mio script non funziona :-( potete aiutarmi per favore?
Il plug in dovrebbe fungere cosi' :
- creo un widget da inserire in side bar
- do la possibilità all utente di inserire Titolo / citta / apikey
- mi dovrebbe ritornare la temperatura etc etc della citta richiesta

non succede niente sembra come se l apikey non funzionasse
PHP:
<?php
/*
Plugin Name: meteo plugin
Plugin URI: ###
Description:
Version: 1.0
Author:
Author URI:
License: GPL2
*/

class Wunderground_Widget extends WP_Widget {

public function __construct() {
parent::__construct(
'wunderground_widget',
'Wunderground Widget',
array( 'description' => 'A Widget for displaying the current weather using the Wunderground API' )
);
}

public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$api_key = $instance['api_key'];
$location = $instance['location'];

wp_register_style('meteo-style', plugins_url('meteo/meteo.css', dirname(__FILE__)));
wp_enqueue_style('meteo-style');

$api_url = 'http://api.wunderground.com/api/'.$api_key.'/conditions/forecast/q/'.$location.'.json';
$response = wp_remote_get( $api_url );

$wunderground = json_decode($response['body']);

echo $before_widget;
?>
<div class='wunderground-widget'>
<?php if(isset($title)){ ?>
<h3 class='widget-title'><?php echo $title ?></h3>
<?php
}

$current = $wunderground->{'current_observation'};
$location = $current->{'display_location'}->{'full'};
$temp = $current->{'feelslike_c'};
$wind = $current->{'wind_kph'};
$wind_dir = $current->{'wind_dir'};
$humidity = $current->{'relative_humidity'};
$summary = $current->{'weather'};

$forecast = $wunderground->{'forecast'}->{'txt_forecast'}->{'forecastday'}[0];
$icon = $forecast->{'icon'};
$icon_url = $forecast->{'icon_url'};
$text = $forecast->{'fcttext_metric'};
?>
<div>
<div class="temp"><?php echo $temp ?>&deg;C <img src="<?php echo $icon_url ?>" alt="<?php echo $icon ?>"/></div>
<div class="location"><?php echo $location ?></div>
<div class="wind">Vento: <?php echo $wind ?>kph (<?php echo $wind_dir ?>)</div>
<div class="humidity">Umido': <?php echo $humidity ?></div>
<div class="summary" title="<?php echo $text ?>">Sunto: <?php echo $summary ?></div>
</div>
</div>
<?php
echo $after_widget;
}

public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['api_key'] = strip_tags( $new_instance['api_key'] );
$instance['location'] = strip_tags( $new_instance['location'] );
return $instance;
}

public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = 'New title';
}

if ( isset( $instance[ 'api_key' ] ) ) {
$api_key = $instance[ 'api_key' ];
}
else {
$api_key = '';
}

if ( isset( $instance[ 'location' ] ) ) {
$location = $instance[ 'location' ];
}
else {
$location = '';
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'location' ); ?>"><?php _e( 'Location:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'location' ); ?>" name="<?php echo $this->get_field_name( 'location' ); ?>" type="text" value="<?php echo esc_attr( $location ); ?>" />

<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />

<label for="<?php echo $this->get_field_id( 'api_key' ); ?>"><?php _e( 'API Key:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'api_key' ); ?>" name="<?php echo $this->get_field_name( 'api_key' ); ?>" type="text" value="<?php echo esc_attr( $api_key ); ?>" />
</p>
<?php
}

}

function wunderground_widgets_init(){
register_widget( 'Wunderground_Widget' );
}
add_action( 'widgets_init', 'wunderground_widgets_init' );
 
Ultima modifica di un moderatore:

Max 1

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
29 Feb 2012
4.449
338
83
@michele81
Da regolamento del forum, come tutti noi sei tenuto ad usare il tag
code-gif.6007
o il tag
php-png.6009
per il PHP, quando posti del codice, oppure la funzione codice dalla barra degli strumenti
box-inserisci-2-png-jpg.6008


Inoltre ti prego di leggere attentamente il regolamento generale del forum e quello di sezione dove posti prima di continuare
Grazie

Per questa volta te lo sistemo io ma mi raccomando per il futuro
 

Max 1

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
29 Feb 2012
4.449
338
83
Oltre ai tag non devi aprire due discussioni uguali ne nella stessa sezione ne in sezioni diverse
 
Discussioni simili
Autore Titolo Forum Risposte Data
Spown [WordPress] Problemi visualizzazione su più browser + voci menu in movimento WordPress 1
A [WordPress] problemi con xampp WordPress 2
C [WordPress] Url vulnerability e problemi sito da mobile WordPress 0
giuseppe_123 [HTML] Problemi wordpress WordPress 2
base90 [WordPress]Problemi con url home differente url installazione WordPress WordPress 1
L [WordPress] Dividere articoli in più pagine, problemi SEO? WordPress 2
enzonero Problemi con la visualizzazione del sito fatto con WordPress WordPress 1
enzonero Problemi con la visualizzazione del sito fatto con Wordpress WordPress 1
S Problemi spostamento wordpress WordPress 1
F Aiuto! Problemi filtraggio portfolio wordpress Presentati al Forum 0
felino [Wordpress 3.9.1] Problemi con l'editor di post/pagine WordPress 6
V [WordPress] Woocommerce problemi con le immagini WordPress 3
P WordPress: problemi con "Aggiungi Media" WordPress 2
glm2006ITALY Guida Il proprio sito WordPress è professionale? WordPress 0
R Plugin di base per WordPress WordPress 0
felino [Wordpress] Gallery con foto selezionabili dall'utente WordPress 0
Lino80 [Retribuito] Cerco programmatore php per modifica/inserimento funzione/valori da un plugin importer wordpress Offerte e Richieste di Lavoro e/o Collaborazione 0
R Dubbi su siti sviluppati con Wordpress e con codice WordPress 6
Z Cerco ecommerce gratuito meglio se realizzato con Woocommerce di Wordpress. E-Commerce 0
peppe0703 Come Estrarre dati da db wordpress e richiamarli in html esterno HTML e CSS 0
A WordPress e immagini Hosting 0
comunic_hiara Meglio Wordpress o Shopify? Guadagnare col Sito 1
S Sito Wordpress creato in localhost PHP 1
D Come estendere la tariffa per Wordpress con Visa? Hosting 1
J Devo scegliere Wordpress o Wix o Hostinger? Hosting 0
S Cerco Programmatore wordpress Offerte e Richieste di Lavoro e/o Collaborazione 0
Shyson Wordpress conta più messaggi di quelli che ci sono WordPress 1
S WORDPRESS NON FA INSTALLARE PIU NULLA WordPress 9
D Pagina non trovata Wordpress WordPress 7
Gabriele Visioli Differenza tra hosting e hosting WordPress Hosting 4
J Inserire blog wordpress in angular CMS (Content Management System) 0
H Hosting per Wordpress 2020 Hosting 5
C wordpress + woocommerce WordPress 4
S [Vendo] Sito Wordpress Altri Annunci 0
S [Vendo] PopcornTime Wordpress Clone Altri Annunci 0
P HTML integrazione wordpress HTML e CSS 0
Shyson Spostare filtro php di WordPress WordPress 0
Web93 CREARE SITO WEB COMICS CON WORDPRESS WordPress 0
A Cornici immagini per sito Web Wordpress WordPress 1
G sito wordpress da remoto a locale con xampp WordPress 2
atipika INSERIRE ICONE DOWNLOAD E STAMPA WORDPRESS WordPress 10
R Richiesta per sviluppo plugin Wordpress Offerte e Richieste di Lavoro e/o Collaborazione 9
gandalf1959 ricercare porzioni di codice da sito gestito con WordPress WordPress 11
L [CERCO] Creare blog su WordPress con tema Divi Offerte e Richieste di Lavoro e/o Collaborazione 3
M [Wordpress] Slider Revolution automatic link WordPress 0
felino [Wordpress] Modifica main color del template WordPress 8
felino [Wordpress] Sito web con codice malevolo WordPress 7
felino [Wordpress] Title dinamico per pagina WordPress 0
C Offro Installazione Wordpress Gratis! + Template Offerte e Richieste di Lavoro e/o Collaborazione 0
ecosito [WordPress] Polylang sballa il tema Avada WordPress 1

Discussioni simili