[wp-trac] [WordPress Trac] #14876: wp_get_sidebars_widgets() assumes that widgets are enabled
WordPress Trac
noreply at wordpress.org
Thu Apr 17 19:47:57 UTC 2014
#14876: wp_get_sidebars_widgets() assumes that widgets are enabled
--------------------------+-----------------------------
Reporter: nacin | Owner:
Type: defect (bug) | Status: reopened
Priority: lowest | Milestone: Future Release
Component: Widgets | Version:
Severity: minor | Resolution:
Keywords: | Focuses:
--------------------------+-----------------------------
Comment (by needle):
I think the following is related to this ticket, though it may be an edge
case:
I have encountered a fatal error in
`WP_Customize_Widgets->customize_register()` when opening the Theme
Customizer. This was after switching to a theme that has only one (empty)
widget area. I confirmed that `$sidebars_widgets` in
`wp_get_sidebars_widgets()` is not set, which throws the error when
customize_register() tries to include the result in an `array_merge()`.
Thankfully there's a filter, so I can avoid the error with the following:
{{{
/**
* Avoid fatal error on Theme Customizer
*/
function my_sidebars_widgets( $array ) {
if ( !is_array( $array ) ) {
$array = array();
}
return $array;
}
add_filter( 'sidebars_widgets', 'my_sidebars_widgets', 999 );
}}}
Nonetheless, it would seem that some defensiveness is necessary to ensure
that an array is always returned by `wp_get_sidebars_widgets()` even if it
is empty. Could be as simple as declaring `$sidebars_widgets = array()` at
the top of the function.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/14876#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list