1

I had some basic widgets registered and assigned to sidebars which were working prior to upgrading to WordPress 4.3.

class Footer_Contact_Widget extends WP_Widget {
    public function __construct() {
        parent::WP_Widget('contact_details','Contact Details','description=Contact Details for Footer');
    }

    public function form( $instance ) {
        // outputs the options form on admin
    }

    public function update( $new_instance, $old_instance ) {
        // processes widget options to be saved
    }

    public function widget( $args, $instance ) {
        echo "Output stuff";
    }
}

These stopped working presumably in part due to the deprecated PHP4-style constructors. So I updated my constructor call accordingly:

    public function __construct() {
        parent::__construct('contact_details','Contact Details','description=Contact Details for Footer');
    }

Now the constructor runs correctly but my widget() method still doesn't.

In digging down to the parent WP_Widget class defined in wp-includes/widgets.php it appears the WP_Widget::display_callback() method is bailing out because my widgets don't have "settings":

public function display_callback( $args, $widget_args = 1 ) {
    if ( is_numeric( $widget_args ) ) {
            $widget_args = array( 'number' => $widget_args );
    }

    $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );

    $this->_set( $widget_args['number'] );
    $instances = $this->get_settings();

    if ( isset( $instances[ $this->number ] ) ) {
        # Normally proceeds to call ->widget() but does not evaluate

If I have two widgets like this, the value of $instances is something like array(2) { [2]=> NULL [3]=> NULL }. The NULL value means isset( $instances[ $this->number ] ) is false.

But the thing is my widgets don't have settings. I'm a bit lost as to what else might have changed in this version of WordPress.

1
  • Removing my empty form() and update() methods allowed the widget to function again, although it had to be removed from the sidebar and added again. Not sure why.
    – rebroken
    Commented Aug 29, 2015 at 4:53

0

Your Answer

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

Browse other questions tagged or ask your own question.