Convert the old style widgets order array only when loading the widgets screen, fixes #10300 for trunk
git-svn-id: http://svn.automattic.com/wordpress/trunk@11691 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e0e697974e
commit
a85254b70c
|
@ -885,7 +885,7 @@ function dynamic_sidebar($index = 1) {
|
||||||
function is_active_widget($callback = false, $widget_id = false, $id_base = false, $skip_inactive = true) {
|
function is_active_widget($callback = false, $widget_id = false, $id_base = false, $skip_inactive = true) {
|
||||||
global $wp_registered_widgets;
|
global $wp_registered_widgets;
|
||||||
|
|
||||||
$sidebars_widgets = wp_get_sidebars_widgets(false);
|
$sidebars_widgets = wp_get_sidebars_widgets();
|
||||||
|
|
||||||
if ( is_array($sidebars_widgets) ) {
|
if ( is_array($sidebars_widgets) ) {
|
||||||
foreach ( $sidebars_widgets as $sidebar => $widgets ) {
|
foreach ( $sidebars_widgets as $sidebar => $widgets ) {
|
||||||
|
@ -935,7 +935,7 @@ function is_dynamic_sidebar() {
|
||||||
*/
|
*/
|
||||||
function is_active_sidebar( $index ) {
|
function is_active_sidebar( $index ) {
|
||||||
$index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index);
|
$index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index);
|
||||||
$sidebars_widgets = wp_get_sidebars_widgets(false);
|
$sidebars_widgets = wp_get_sidebars_widgets();
|
||||||
if ( isset($sidebars_widgets[$index]) && !empty($sidebars_widgets[$index]) )
|
if ( isset($sidebars_widgets[$index]) && !empty($sidebars_widgets[$index]) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -953,25 +953,26 @@ function is_active_sidebar( $index ) {
|
||||||
* @since 2.2.0
|
* @since 2.2.0
|
||||||
* @access private
|
* @access private
|
||||||
*
|
*
|
||||||
* @param bool $update Optional, default is true. Whether to save upgrade of widget array list.
|
* @param bool $update Optional, deprecated.
|
||||||
* @return array Upgraded list of widgets to version 2 array format.
|
* @return array Upgraded list of widgets to version 3 array format when called from the admin.
|
||||||
*/
|
*/
|
||||||
function wp_get_sidebars_widgets($update = true) {
|
function wp_get_sidebars_widgets($deprecated = true) {
|
||||||
global $wp_registered_widgets, $wp_registered_sidebars, $_wp_sidebars_widgets;
|
global $wp_registered_widgets, $wp_registered_sidebars, $_wp_sidebars_widgets;
|
||||||
|
|
||||||
// If loading from front page, consult $_wp_sidebars_widgets rather than options
|
// If loading from front page, consult $_wp_sidebars_widgets rather than options
|
||||||
// to see if wp_convert_widget_settings() has made manipulations in memory.
|
// to see if wp_convert_widget_settings() has made manipulations in memory.
|
||||||
if ( is_admin() ) {
|
if ( !is_admin() ) {
|
||||||
$sidebars_widgets = get_option('sidebars_widgets', array());
|
|
||||||
} else {
|
|
||||||
if ( empty($_wp_sidebars_widgets) )
|
if ( empty($_wp_sidebars_widgets) )
|
||||||
|
$_wp_sidebars_widgets = get_option('sidebars_widgets', array());
|
||||||
|
|
||||||
|
$sidebars_widgets = $_wp_sidebars_widgets;
|
||||||
|
} else {
|
||||||
$sidebars_widgets = get_option('sidebars_widgets', array());
|
$sidebars_widgets = get_option('sidebars_widgets', array());
|
||||||
else
|
|
||||||
$sidebars_widgets = &$_wp_sidebars_widgets;
|
|
||||||
}
|
|
||||||
$_sidebars_widgets = array();
|
$_sidebars_widgets = array();
|
||||||
|
|
||||||
if ( !isset($sidebars_widgets['array_version']) )
|
if ( isset($sidebars_widgets['wp_inactive_widgets']) )
|
||||||
|
$sidebars_widgets['array_version'] = 3;
|
||||||
|
elseif ( !isset($sidebars_widgets['array_version']) )
|
||||||
$sidebars_widgets['array_version'] = 1;
|
$sidebars_widgets['array_version'] = 1;
|
||||||
|
|
||||||
switch ( $sidebars_widgets['array_version'] ) {
|
switch ( $sidebars_widgets['array_version'] ) {
|
||||||
|
@ -1024,18 +1025,21 @@ function wp_get_sidebars_widgets($update = true) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign to each unmatched registered sidebar the first available orphan
|
// move the rest to wp_inactive_widgets
|
||||||
unset( $sidebars_widgets[ 'array_version' ] );
|
if ( !isset($_sidebars_widgets['wp_inactive_widgets']) )
|
||||||
while ( ( $sidebar = array_shift( $sidebars ) ) && $widgets = array_shift( $sidebars_widgets ) )
|
$_sidebars_widgets['wp_inactive_widgets'] = array();
|
||||||
$_sidebars_widgets[ $sidebar ] = $widgets;
|
|
||||||
|
if ( !empty($sidebars_widgets) ) {
|
||||||
|
foreach ( $sidebars_widgets as $lost => $val ) {
|
||||||
|
if ( is_array($val) )
|
||||||
|
$_sidebars_widgets['wp_inactive_widgets'] = array_merge( (array) $_sidebars_widgets['wp_inactive_widgets'], $val );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$_sidebars_widgets['array_version'] = 3;
|
|
||||||
$sidebars_widgets = $_sidebars_widgets;
|
$sidebars_widgets = $_sidebars_widgets;
|
||||||
unset($_sidebars_widgets);
|
unset($_sidebars_widgets);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ( $update && is_admin() )
|
|
||||||
update_option('sidebars_widgets', $sidebars_widgets);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset($sidebars_widgets['array_version']) )
|
if ( isset($sidebars_widgets['array_version']) )
|
||||||
|
@ -1086,9 +1090,8 @@ function wp_get_widget_defaults() {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function wp_convert_widget_settings($base_name, $option_name, $settings) {
|
function wp_convert_widget_settings($base_name, $option_name, $settings) {
|
||||||
global $_wp_sidebars_widgets;
|
|
||||||
// This test may need expanding.
|
// This test may need expanding.
|
||||||
$single = false;
|
$single = $changed = false;
|
||||||
if ( empty($settings) ) {
|
if ( empty($settings) ) {
|
||||||
$single = true;
|
$single = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1110,7 +1113,7 @@ function wp_convert_widget_settings($base_name, $option_name, $settings) {
|
||||||
$sidebars_widgets = get_option('sidebars_widgets');
|
$sidebars_widgets = get_option('sidebars_widgets');
|
||||||
} else {
|
} else {
|
||||||
if ( empty($GLOBALS['_wp_sidebars_widgets']) )
|
if ( empty($GLOBALS['_wp_sidebars_widgets']) )
|
||||||
$GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets');
|
$GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array());
|
||||||
$sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets'];
|
$sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1119,13 +1122,14 @@ function wp_convert_widget_settings($base_name, $option_name, $settings) {
|
||||||
foreach ( $sidebar as $i => $name ) {
|
foreach ( $sidebar as $i => $name ) {
|
||||||
if ( $base_name == $name ) {
|
if ( $base_name == $name ) {
|
||||||
$sidebars_widgets[$index][$i] = "$name-2";
|
$sidebars_widgets[$index][$i] = "$name-2";
|
||||||
|
$changed = true;
|
||||||
break 2;
|
break 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_admin() )
|
if ( is_admin() && $changed )
|
||||||
update_option('sidebars_widgets', $sidebars_widgets);
|
update_option('sidebars_widgets', $sidebars_widgets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue