Widgets: Don't try mapping empty sidebars.

Fixes a bug where the mapping logic would try mapping empty sidebars, resulting in PHP warnings.

Props ionvv, chetan200891 for initial patch.
See #42603.

Merges [42362] to the 4.9 branch.


Built from https://develop.svn.wordpress.org/branches/4.9@42363


git-svn-id: http://core.svn.wordpress.org/branches/4.9@42192 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Konstantin Obenland 2017-12-04 20:17:42 +00:00
parent 1fdfabf74c
commit 2afecbb253

View File

@ -1294,6 +1294,9 @@ function wp_map_sidebars_widgets( $existing_sidebars_widgets ) {
if ( is_array( $old_sidebars_widgets ) ) {
// Remove empty sidebars, no need to map those.
$old_sidebars_widgets = array_filter( $old_sidebars_widgets );
// Only check sidebars that are empty or have not been mapped to yet.
foreach ( $new_sidebars_widgets as $new_sidebar => $new_widgets ) {
if ( array_key_exists( $new_sidebar, $old_sidebars_widgets ) && ! empty( $new_widgets ) ) {