how to extend a WP_widget twice

You have to make sure that all of your parameters are passed all the way through to the WP_Widget class. Your code is very truncated but I am pretty sure that is what you are doing wrong.

The widget code below works– it doesn’t do much of anything, but it works. See if you can use it as a template to sort out your own code.

  class Foo extends WP_Widget {
    /*constructs etc*/
    function __construct($id = 'twidg', $descr="Test Widget", $opts = array()) {
      $widget_opts = array();
      parent::__construct($id,$descr,$widget_opts);
      /*do stuff*/
    }

    function widget() {
      echo 'test widget';
    }
  }

function rw_cb() {
  register_widget("Foo");
}
add_action('widgets_init', 'rw_cb');

class Bar extends Foo {     
    function __construct() {
      $widget_opts = array();
      parent::__construct('twidgextended','Test Widget 2',$widget_opts);
    }

    function widget() {
      echo 'test widget 2';
    }
}
function rw_cb_2() {
  register_widget("Bar");
}
add_action('widgets_init', 'rw_cb_2');

The code is mostly cribbed from another question. I made minor changes before posting it here.

Leave a Comment