myWeather widget

To create a quick and dirty widget from myWeather wordpress plugin just add the following to the end of myweather.php

  1.  
  2. function widget_weather_init() {
  3.  
  4.     if ( !function_exists(‘register_sidebar_widget’) )
  5.             return;
  6.     register_sidebar_widget(array(‘Weather’, ‘widgets’), ‘widget_weather’);    
  7. }
  8.  
  9. function widget_weather($args)
  10. {
  11.     extract($args);
  12.     echo $before_widget . $before_title . $title . $after_title;
  13.     wp_myweather();
  14.     echo $after_widget;
  15. }
  16.  
  17. add_action(‘widgets_init’, ‘widget_weather_init’);
  18.  

Also the part where you search for the city could be added as a control for the widget but i didn’t relay need it to be .

MyWeather plugin’s homepage.

Update

If you have multiple users with different credentials on your blog and you are the only administrator you can restrict the access to myWeather plugin administration interface by changing the function myweather_to_admin() to look like this (use 10 instead of 1 for required level) :

  1.  
  2. function myweather_to_admin() {
  3.         if (function_exists(‘add_submenu_page’)) {
  4.                 add_submenu_page(‘options-general.php’, ‘myWeather’,
  5.                  ‘myWeather’, 10, basename(__FILE__),‘myweather_admin’);
  6.         }
  7. }
  8.  

Tags:, ,

Related:

Topics: Programming


  1. Eduardo ITALY Windows XP Mozilla Firefox 2.0.0.2 December 6th, 2007 at 3:18 pm

    Stupendo, non ci avevo proprio pensato.
    Se sei daccordo lo inserisco nella prossima versione, naturalmente citandoti fra gli autori (fammi sapere se hai un account su wordpress.com cosi verrai direttamente linkato il tuo profilo)

  2. eti ROMANIA Windows XP Mozilla Firefox 2.0.0.11 December 6th, 2007 at 3:35 pm

    Certo che sono daccordo a inserire le funzioni nella prossima vertione.
    Il mio username su wordpress.com e alpinism, pero se vuoi puoi linkare a questo blog - http://www.erata.net

  3. eti ROMANIA Windows XP Mozilla Firefox 2.0.0.11 February 7th, 2008 at 3:52 pm

    The plugin has been updated by the author to include widget support, but the wigetized version only works with php5. So if you are stuck with php4 manual editing is the way to go.

  4. eti ROMANIA Windows XP Mozilla Firefox 2.0.0.12 March 4th, 2008 at 9:16 pm

    The latest version of the plugin has widget support and it’s working with php4.

  5. Eduardo ITALY Mac OS X Safari 523.15 March 4th, 2008 at 9:35 pm

    Ho già aggiornato i file. Al prossimo update conterrà anche questa modifica.
    Come al solito grazie.

Leave a Reply