小部件自定义保存在小部件本身中。所以除了删除sidebars_widgets
, 您还必须删除小部件中的自定义数据。
$sidebars_widgets = get_option(\'sidebars_widgets\');
foreach ($sidebars_widgets as $key => $value) {
foreach ($value as $widget_id) {
$pieces = explode(\'-\', $widget_id);
$multi_number = array_pop($pieces);
$id_base = implode(\'-\', $pieces);
$widget = get_option(\'widget_\' . $id_base);
//Here it deletes the widget customizations that are linked to an id
unset($widget[$multi_number]);
update_option(\'widget_\' . $id_base, $widget);
}
//Here it erases all the page\'s widget. Set ampty array.
$sidebars_widgets[$key] = array();
}
update_option(\'sidebars_widgets\', $sidebars_widgets);