WordPress at a glance
function is not described

_wp_remove_unregistered_widgets() WP 4.9.0

Compares a list of sidebars with their widgets against a whitelist.

No Hooks.

Return

Array. Sidebars with whitelisted widgets.

Usage

_wp_remove_unregistered_widgets( $sidebars_widgets, $whitelist );
$sidebars_widgets(array) (required)
List of sidebars and their widget instance IDs.
$whitelist(array)
List of widget IDs to compare against. Default: Registered widgets.
Default: array()

Code of wp remove unregistered widgets: wp-includes/widgets.php VER 5.1.1

<?php
function _wp_remove_unregistered_widgets( $sidebars_widgets, $whitelist = array() ) {
	if ( empty( $whitelist ) ) {
		$whitelist = array_keys( $GLOBALS['wp_registered_widgets'] );
	}

	foreach ( $sidebars_widgets as $sidebar => $widgets ) {
		if ( is_array( $widgets ) ) {
			$sidebars_widgets[ $sidebar ] = array_intersect( $widgets, $whitelist );
		}
	}

	return $sidebars_widgets;
}