WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 6 months ago

#38469 new defect (bug)

wp-includes/widgets.php:1208 Undefined index: wp_inactive_widgets

Reported by: onnimonni Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.8
Component: Widgets Keywords: has-patch close 2nd-opinion
Focuses: Cc:

Description

Hey!

Multiple persons can reproduce this error in our company.

After I switch themes I'll get notice about widgets.

It happens in wp-includes/widgets.php:1208

I'm using custom wp-content/install.php which doesn't add any widgets because we don't usually use them at all.

This problem gets fixed when I add this snippet in my mu-plugins:

<?php
add_action( 'init', function() {
    global $sidebars_widgets;
    if (!isset($sidebars_widgets['wp_inactive_widgets'])) {
        $sidebars_widgets['wp_inactive_widgets'] = [];
    }
});

Custom install.php can be found here: https://github.com/devgeniem/better-wp-install-dropin/blob/master/install.php

Details:

$ wp core version
4.6.1

$ php -v
PHP 7.0.12-1

Change History (2)

#1 @onnimonni
3 years ago

This can also be fixed by adding following line to install.php:

<?php
update_option( 'sidebars_widgets', array( 'wp_inactive_widgets' => array() ) );

We should either document this behaviour into codex or core should have fix which handles this situation automatically.

#2 @desrosj
6 months ago

  • Component changed from General to Widgets
  • Keywords has-patch close 2nd-opinion added
  • Version changed from 4.6.1 to 2.8

Thanks for opening this, @onnimonni!

It looks like your custom install script is now correctly adding an empty array to the wp_inactive_widgets key for the sidebars_widgets option.

My initial thought is that this notice should not be fixed. This notice indicates that something has removed that index from the array (or has never set it) and is causing a problem. Also, this was only occurring because your custom installer was not initializing the wp_inactive_widgets index and not due to a bug in core.

Marking as a close candidate pending a second opinion.

Note: See TracTickets for help on using tickets.