Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

wp_set_sidebars_widgets() WordPress Function

The wp_set_sidebars_widgets() function allows you to programmatically set the widgets for a given sidebar. This can be useful in a number of situations, such as when you need to change the widgets in a sidebar based on certain conditions. To use this function, you need to pass in an array of sidebar IDs and an array of widget IDs. The widget IDs need to be in the order you want them to appear in the sidebar. So, if you want the widget with an ID of "foo" to appear first in the sidebar with an ID of "sidebar-1", you would need to have the following: array( 'sidebar-1' => array( 'foo', ), ); If you want to remove all widgets from a sidebar, you can pass an empty array for the sidebar ID. For example, the following code would remove all widgets from the sidebar with an ID of "sidebar-1": array( 'sidebar-1' => array(), );

wp_set_sidebars_widgets( array $sidebars_widgets ) #

Set the sidebar widget option to update sidebars.


Parameters

$sidebars_widgets

(array)(Required)Sidebar widgets and their settings.


Top ↑

Source

File: wp-includes/widgets.php

function wp_set_sidebars_widgets( $sidebars_widgets ) {
	global $_wp_sidebars_widgets;

	// Clear cached value used in wp_get_sidebars_widgets().
	$_wp_sidebars_widgets = null;

	if ( ! isset( $sidebars_widgets['array_version'] ) ) {
		$sidebars_widgets['array_version'] = 3;
	}

	update_option( 'sidebars_widgets', $sidebars_widgets );
}


Top ↑

Changelog

Changelog
VersionDescription
2.2.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.