Opened 22 months ago
Last modified 22 months ago
#57446 new defect (bug)
Theme switch, retrieve_widgets(), and malformed/missing sidebars_widgets leading to fatal error
Reported by: | 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'] );
- https://developer.wordpress.org/reference/functions/retrieve_widgets/
- https://developer.wordpress.org/reference/functions/check_theme_switched/
---
Tested on
WordPress 6.0.3 & 6.1.1
PHP version 7.4, 8.0, 8.1, 8.2
Change History (4)
#2
@
22 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
#4
@
22 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.
Related options prior to the theme switch.
current_theme
theme_mods_enfold-child
No widgets array.
theme_switched
Errors
Attempting to access /wp-admin/widgets.php generates the following error.
Related options after theme switch
Switched to Twenty Twenty-Three
current_theme
theme_mods_twentytwentythree
theme_switched
Errors
Any attempts to interact with the site leads to the following.