Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to be able to register multiple copies of the Quick Search Widget in the code below, so that I can have it multiple sidebars. The code has been taken from a plugin I've downloaded

function quickSearchwidgetform()

{

  include(WP_DSP_ABSPATH . 'wp_search_wiget_form.php');

}



function widget_dspquicksearch($args) {

  extract($args);

  echo $before_widget;

  echo $before_title;?>
Quick Search<?php echo $after_title;

  quickSearchwidgetform();

  echo $after_widget;

}

function dspquicksearch_init()

{

wp_register_sidebar_widget(

    'dsp_quick_search_widget',        // your unique widget id

    'Quick Search Widget',          // widget name

    'widget_dspquicksearch',  // callback function

    array(                  // options

        'description' => 'A Quick Search widget that displays dsp dating quick Search form.'

    )

);  

}

add_action("plugins_loaded", "dspquicksearch_init");

Now I've read in the codex that the new updated method of registering a widget, should be done by register_widget() - however, when I update the code below to use this, the widgets page in my admin screen goes completely white.

Admittedly I may be out of my depth here, but am keen to learn how to fix this. Any tips would be greatly appreciated.

Thank you

share|improve this question
add comment

1 Answer

You really need to be using the Widget API.

Here is a widget shell to get you started.

class WPSE_Widget_Shell extends WP_Widget {

  function __construct() {
    $opts = array(
      'description' => 'Brief description; shows on the backend'
    );
    parent::WP_Widget(
      'widget-id',
      'Widget Name', // shows on the backend
      $opts
    );
  }

  function form($instance) {
    echo 'backend widget form (optional if you have not user configurable options)';
  }

  function update($new_instance,$old_instance) {
    // Process backend form data
    // optional if you don't have a 'form' method
  }

  function widget($args,$instance) {
    echo 'Front end widget display';
  }

}
function register_my_widgets() {
  register_widget('WPSE_Widget_Shell');
}
add_action('widgets_init','register_my_widgets');

You are extending the widget class at wp-includes/widgets.php so it is good to keep an eye on the parent class. You can use the default widgets as patterns.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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