Make WordPress Core

Opened 19 months ago

Last modified 19 months ago

#57446 new defect (bug)

Theme switch, retrieve_widgets(), and malformed/missing sidebars_widgets leading to fatal error

Reported by: verygoode's profile verygoode Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.1.1
Component: Widgets Keywords:
Focuses: Cc:

Description

Working with a user that began encountering fatals when accessing widgets.

During troubleshooting on a test site, they switched the theme which led to the following error.

Fatal error: Uncaught Error: Cannot unset string offsets in /wordpress/core/6.1.1/wp-includes/widgets.php:1324
Stack trace:
#0 /wordpress/core/6.1.1/wp-includes/widgets.php(1287): retrieve_widgets(true)
#1 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(309): _wp_sidebars_changed('enfold-child')
#2 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)
#3 /wordpress/core/6.1.1/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
#4 /wordpress/core/6.1.1/wp-includes/theme.php(3380): do_action('after_switch_th...', 'enfold-child', Object(WP_Theme))
#5 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(307): check_theme_switched('')
#6 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)
#7 /wordpress/core/6.1.1/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
#8 /wordpress/core/6.1.1/wp-settings.php(598): do_action('init')
#9 phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1336): require('/wordpress/core...')
#10 phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1254): WP_CLI\Runner->load_wordpress()
#11 phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#12 phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/bootstrap.php(78): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#13 phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#14 phar:///usr/local/bin/wp-cli/php/boot-phar.php(11): include('phar:///usr/loc...')
#15 /usr/local/bin/wp-cli(4): include('phar:///usr/loc...')
#16 {main}
  thrown in /wordpress/core/6.1.1/wp-includes/widgets.php on line 1324

After this error was triggered, and perhaps due to opcache, it has been difficult to interact with the site.

Attempts to utilize WP-CLI, adjust theme related settings in the _options table, and removing theme files have not been successful in getting the site responsive again.

Conditions on the site appear to have led to a string to be present when widgets.php's retrieve_widgets() attempts unset( $sidebars_widgets['array_version'] );

---
Tested on

WordPress 6.0.3 & 6.1.1
PHP version 7.4, 8.0, 8.1, 8.2

Change History (4)

#1 @verygoode
19 months ago

Related options prior to the theme switch.

current_theme

Enfold Child

theme_mods_enfold-child

No widgets array.

a:2:{s:18:"nav_menu_locations";a:3:{s:4:"avia";i:73;s:5:"avia2";i:0;s:5:"avia3";i:0;}s:18:"custom_css_post_id";i:2960;}

theme_switched

empty

Errors

Attempting to access /wp-admin/widgets.php generates the following error.

[11-Jan-2023 17:16:51 UTC] PHP Warning:  Invalid argument supplied for foreach() in /wordpress/core/6.1.1/wp-admin/widgets-form.php on line 82
[11-Jan-2023 17:16:51 UTC] PHP Fatal error:  Uncaught Error: Cannot unset string offsets in /wordpress/core/6.1.1/wp-includes/widgets.php:1324
Stack trace:
#0 /wordpress/core/6.1.1/wp-admin/widgets-form.php(121): retrieve_widgets()
#1 /wordpress/core/6.1.1/wp-admin/widgets.php(34): require('/wordpress/core...')
#2 {main}
  thrown in /wordpress/core/6.1.1/wp-includes/widgets.php on line 1324

Related options after theme switch

Switched to Twenty Twenty-Three

current_theme

Twenty Twenty-Three

theme_mods_twentytwentythree

a:2:{i:0;b:0;s:18:"nav_menu_locations";a:0:{}}

theme_switched

enfold-child

Errors
Any attempts to interact with the site leads to the following.

Fatal error: Uncaught Error: Cannot unset string offsets in /wordpress/core/6.1.1/wp-includes/widgets.php:1324
Stack trace:
#0 /wordpress/core/6.1.1/wp-includes/widgets.php(1287): retrieve_widgets(true)
#1 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(310): _wp_sidebars_changed('Enfold Child')
#2 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#3 /wordpress/core/6.1.1/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#4 /wordpress/core/6.1.1/wp-includes/theme.php(3395): do_action('after_switch_th...', 'Enfold Child', Object(WP_Theme))
#5 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(308): check_theme_switched('')
#6 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#7 /wordpress/core/6.1.1/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#8 /wordpress/core/6.1.1/wp-settings.php(617): do_action('init')
#9 phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1336): require('/wordpress/core...')
#10 phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1254): WP_CLI\Runner->load_wordpress()
#11 phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#12 phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/bootstrap.php(78): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#13 phar:///usr/local/bin/wp-cli/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#14 phar:///usr/local/bin/wp-cli/php/boot-phar.php(11): include('phar:///usr/loc...')
#15 /usr/local/bin/wp-cli(4): include('phar:///usr/loc...')
#16 {main}
  thrown in /wordpress/core/6.1.1/wp-includes/widgets.php on line 1324
Error: There has been a critical error on this website.Learn more about troubleshooting WordPress. There has been a critical error on this website.

#2 @verygoode
19 months ago

  • Summary changed from Theme Switch, retrieve_widgets() Leading to Fatal Error to Theme switch, retrieve_widgets(), and malformed/missing sidebars_widgets leading to fatal error

#3 @verygoode
19 months ago

  • Component changed from General to Widgets

#4 @verygoode
19 months ago

To prevent the issue on a site that hasn't switched themes yet, it's possible to repair theme_mods by adding a sidebars_widgets array.

E.g. a:3:{s:18:"nav_menu_locations";a:3:{s:4:"avia";i:73;s:5:"avia2";i:0;s:5:"avia3";i:0;}s:18:"custom_css_post_id";i:2960;s:16:"sidebars_widgets";a:0:{}}

However, for a site already affected, it doesn't make an immediate difference. It may be necessary to allow caches to clear in some environments -- or try adjusting theme_switched to false as well.

Seems retrieve_widgets()'s unset( $sidebars_widgets['array_version'] ); needs safeguards like what was added to wp_get_sidebars_widgets() via https://core.trac.wordpress.org/changeset/14320

I can return and try to work on a patch later.

Last edited 19 months ago by verygoode (previous) (diff)
Note: See TracTickets for help on using tickets.