$number =
preg_replace( '/.+?-([0-9]+)$/', '$1',
$widget_id );
// Only keep active and default widgets.
if ( is_numeric( $number ) &&
(int) $number < 2
) { unset( $lost_widgets[ $key ] );
} } $sidebars_widgets['wp_inactive_widgets'
] =
array_merge( $lost_widgets,
(array) $sidebars_widgets['wp_inactive_widgets'
] );
if ( 'customize' !==
$theme_changed ) { // Update the widgets settings in the database.
wp_set_sidebars_widgets( $sidebars_widgets );
} return $sidebars_widgets;
}/**
* Compares a list of sidebars with their widgets against an allowed list.
*
* @since 4.9.0
* @since 4.9.2 Always tries to restore widget assignments from previous data, not just if sidebars needed mapping.
*
* @param array $existing_sidebars_widgets List of sidebars and their widget instance IDs.
* @return array Mapped sidebars widgets.
*/