wp_find_widgets_sidebar()WP 5.8.0

Finds the sidebar that a given widget belongs to.

Хуков нет.

Возвращает

Строку|null. The found sidebar's ID, or null if it was not found.

Использование

wp_find_widgets_sidebar( $widget_id );
$widget_id(строка) (обязательный)
The widget ID to look for.

Список изменений

С версии 5.8.0 Введена.

Код wp_find_widgets_sidebar() WP 6.0

function wp_find_widgets_sidebar( $widget_id ) {
	foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) {
		foreach ( $widget_ids as $maybe_widget_id ) {
			if ( $maybe_widget_id === $widget_id ) {
				return (string) $sidebar_id;
			}
		}
	}

	return null;
}