0

I am talking about making a widget which extends a child widget of WP_Widget.

Using this as reference: https://wordpress.stackexchange.com/questions/101438/how-to-extend-a-wp-widget-twice

Example:

My_WidgetBase extends WP_Widget

My_Widget extends My_WidgetBase

I want to know how to get My_Widget to show up with my other widgets (it is not currently). I have gotten My_WidgetBase to work.

This is important for my framework. I understand that widget(), update(), and form() must be overridden, but I could not find anything about making a grandchild of WP_Widget anywhere.

Example:

class My_WidgetBase extends WP_Widget {

    public function __construct($id = 'my-widget-base', $desc = 'My WidgetBase', $opts = array()) {
        $widget_ops = array();
        parent::__construct( $id, $desc, $widget_ops );
    }

    public function widget( $args, $instance ) {
        die('function WP_Widget::widget() must be over-ridden in a sub-class.');
    }


    public function update( $new_instance, $old_instance ) {
        return $new_instance;
    }


    public function form( $instance ) {
        echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>';
        return 'noform';
    }

}

    function RegisterMyWidgets() {
        register_widget('My_WidgetBase');
    }

add_action( 'widgets_init', 'RegisterMyWidgets' );
Community
  • 1
  • 1
aus
  • 69
  • 1
  • 11
  • Are you registering `Bar`? You should do that using `function register_bar_widget() { register_widget( 'Bar' ); } add_action( 'widgets_init', 'register_bar_widget' );` – Felipe Elia Feb 24 '16 at 21:27
  • Yes, I'm using add_action( 'widgets_init', function(){ register_widget( 'My_Widget' ); }); in each of my classes. – aus Feb 24 '16 at 21:39
  • I believe you are changing the 'My_Widget' string in there, right? :P Could you add some code to your question? Maybe it's just a typo or something like that. – Felipe Elia Feb 24 '16 at 21:56
  • Yes I am changing 'My_Widget' for each child, grandchild, etc. I'm not at the computer I have these files stored on, but I have a working child widget and I am just trying to figure out how to make a grandchild. If it should be as easy as making a child again, then yes, maybe I have a typo :). – aus Feb 25 '16 at 00:34

1 Answers1

0

Solved digging further into this thread: https://wordpress.stackexchange.com/questions/101438/how-to-extend-a-wp-widget-twice

The problem was not with my implementation of the classes, but how I included the parent in my framework. I was not working with both child and grandchild in the same php file, but two separate files with different directories.

Solving this problem was a matter of using require_once() correctly in the directory of my grandchild class.

Community
  • 1
  • 1
aus
  • 69
  • 1
  • 11