2

I have read a lot of turorials an even the codex widget API, but can't solve my doubts: What are the really difference writing WorPress 3.x widget plugins? if there exists.

this doubt came when trying to create plugin containing an widget I have actived WP_DEBUG and saw the notice that register_sidebar_widget() is deprecated and I should use wp_register_sidebar_widget() instead.

So I have changed and now I get:

Notice: Uninitialized string offset: 0 in /.../wp-content/plugins/raz/index.php on line 54

Notice: Uninitialized string offset: 0 in /.../wp-content/plugins/raz/index.php on line 55

Notice: Uninitialized string offset: 0 in /.../wp-content/plugins/raz/index.php on line 55

Here is the code:

<?php

// widget to show an iframe containing Brazilian CPTEC weather forecast
function previsao_tempo_cptec_widget_display($args) {

  // print some HTML for the widget to display here
  print $args['before_widget'];
  print $args['before_title'] . "Previsão IN TITLE do Tempo - CPTEC" . $args['after_title'];

  //  print "content of the widget";
  print '<center><!-- Widget Previs&atilde;o de Tempo CPTEC/INPE --><iframe allowtransparency="true" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="http://www.cptec.inpe.br/widget/widget.php?p=4599&w=h&c=909090&f=ffffff" height="200px" width="215px"></iframe><noscript>Previs&atilde;o de <a href="http://www.cptec.inpe.br/cidades/tempo/4599">Santa Maria/RS</a> oferecido por <a href="http://www.cptec.inpe.br">CPTEC/INPE</a></noscript><!-- Widget Previs&atilde;o de Tempo CPTEC/INPE --></center>';
  print $args['after_widget'];   

}

// Activate the sidebar
wp_register_sidebar_widget(    
    'TempoCPTEC_1',  
    'Previsão de Tempo - CPTEC',     
    'previsao_tempo_cptec_widget_display',  
    array(
        'description' => "Este  widget mostra a previsão de Tempo  pelo CPTEC - INPE/BR"      
    ),
    array(
    'before_widget' => '<li>',
    'after_widget'  => '</li>',
    'before_title'  => '<h2 class="widgettitle">',
    'after_title'   => '</h2>'
    )
);


// Loads the widget
add_action('widgets_init','previsao_tempo_cptec_widget_display');
?>

Other doubt, why this widget is always displayed in the top of my website and in the sidebar widgets also?

Thanks for any incoming handy answer.

0

1 Answer 1

3

As per your other question rather than trying to use older API to implement widgets it is better to use newer and current approach as per Widgets API in Codex.

The difference is that newer code is more reliable and more functional (allows to easily have more complex features, such as multiple instances of the widget).

So issues with your code example are probably not worth fixing, better to just move to using currently suggested way.

1
  • Thanks Rarst,I have passe all last night reading and rewriting the code using current approach. Now it works perfectly. Again, thanks for your words and suggestion. Commented Jul 3, 2011 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.