_wp_remove_unregistered_widgets() WordPress Function

The wp_remove_unregistered_widgets() function allows you to remove any widgets that have not been registered with the WordPress widget API. This can be useful if you want to clean up your widget area and only display widgets that you know are safe and compatible with your theme.

_wp_remove_unregistered_widgets( array $sidebars_widgets, array $allowed_widget_ids = array() ) #

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


Parameters

$sidebars_widgets

(array)(Required)List of sidebars and their widget instance IDs.

$allowed_widget_ids

(array)(Optional) List of widget IDs to compare against. Default: Registered widgets.

Default value: array()


Top ↑

Return

(array) Sidebars with allowed widgets.


Top ↑

Source

File: wp-includes/widgets.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;
}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.