WordPress at Your Fingertips
function is not described

_wp_remove_unregistered_widgets() WP 4.9.0

Compares a list of sidebars with their widgets against an allowed list.

This is an internal function for using it by WP core itself. It's not recommended to use this function in your code.

No Hooks.

Return

Array. Sidebars with allowed widgets.

Usage

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

Changelog

Since 4.9.0 Introduced.

Code of _wp_remove_unregistered_widgets() WP 5.8

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

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

	return $sidebars_widgets;
}