[wp-trac] Re: [WordPress Trac] #10300: Optimization in
wp_get_sidebars_widgets() corrupts the widgets
WordPress Trac
wp-trac at lists.automattic.com
Wed Jul 1 20:46:14 UTC 2009
#10300: Optimization in wp_get_sidebars_widgets() corrupts the widgets
-------------------------------+--------------------------------------------
Reporter: Denis-de-Bernardy | Owner: azaozz
Type: defect (bug) | Status: new
Priority: normal | Milestone: 2.8.1
Component: Widgets | Version: 2.8
Severity: normal | Keywords: commit
-------------------------------+--------------------------------------------
Changes (by Denis-de-Bernardy):
* keywords: => commit
Comment:
Rewrote my widget upgrade scripts, and it's working like a charm with
10300.2.diff applied. With your own patch (10300.3.patch) applied, the
global contains filtered values, and I expect this'll eventually lead to
bugs.
{{{
function init() {
if ( get_option('widget_nav_menu') === false ) {
foreach ( array(
'nav_menus' => 'upgrade',
) as $ops => $method ) {
if ( get_option($ops) !== false ) {
$this->alt_option_name = $ops;
add_filter('option_' . $ops,
array(get_class($this), $method));
break;
}
}
}
} # init()
function nav_menu() {
$widget_ops = array(
'classname' => 'nav_menu',
'description' => __("A navigation menu", 'nav-
menus'),
);
$control_ops = array(
'width' => 330,
);
$this->init();
$this->WP_Widget('nav_menu', __('Nav Menu', 'nav-menus'),
$widget_ops, $control_ops);
} # nav_menu()
function upgrade($ops) {
$widget_contexts = class_exists('widget_contexts')
? get_option('widget_contexts')
: false;
unset($ops['header']);
unset($ops['footer']);
foreach ( $ops as $k => $o ) {
if ( isset($widget_contexts['nav_menu-' . $k]) ) {
$ops[$k]['widget_contexts'] =
$widget_contexts['nav_menu-' . $k];
}
}
$extra = get_option('silo_widgets');
if ( $extra !== false ) {
foreach ( $extra as $k => $o ) {
if ( !isset($ops[$k]) ) {
$ops[$k] = $extra[$k];
if (
isset($widget_contexts['silo_widget-' . $k]) ) {
$ops[$k]['widget_contexts'] = $widget_contexts['silo_widget-' . $k];
}
} else {
unset($extra[$k]);
}
}
}
#global $wp_filter, $_wp_sidebars_widgets;
#$filter_backup = isset($wp_filter['sidebars_widgets']) ?
$wp_filter['sidebars_widgets'] : array();
#unset($wp_filter['sidebars_widgets']);
#$_wp_sidebars_widgets = array();
#$sidebars_widgets = wp_get_sidebars_widgets(false);
#$wp_filter['sidebars_widgets'] = $filter_backup;
#$_wp_sidebars_widgets = array();
global $_wp_sidebars_widgets;
if ( is_admin() ) {
$sidebars_widgets = get_option('sidebars_widgets',
array());
} else {
if ( !$_wp_sidebars_widgets )
wp_get_sidebars_widgets(false);
$sidebars_widgets =& $_wp_sidebars_widgets;
}
$keys = array_keys($extra);
foreach ( $sidebars_widgets as $sidebar => $widgets ) {
if ( !is_array($widgets) )
continue;
foreach ( $keys as $k ) {
$key = array_search("silo_widget-$k",
$widgets);
if ( $key !== false ) {
$sidebars_widgets[$sidebar][$key]
= 'nav_menu-' . $k;
unset($keys[array_search($k,
$keys)]);
}
}
}
#wp_set_sidebars_widgets($sidebars_widgets);
if ( is_admin() )
update_option('sidebars_widgets',
$sidebars_widgets);
return $ops;
} # upgrade()
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/10300#comment:16>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list