Changes from trunk/wp-includes/widgets.php at r11510 to branches/2.8/wp-includes/widgets.php at r11690
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.8/wp-includes/widgets.php
r11510 r11690 886 886 global $wp_registered_widgets; 887 887 888 $sidebars_widgets = wp_get_sidebars_widgets( false);888 $sidebars_widgets = wp_get_sidebars_widgets(); 889 889 890 890 if ( is_array($sidebars_widgets) ) { … … 936 936 function is_active_sidebar( $index ) { 937 937 $index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index); 938 $sidebars_widgets = get_option( 'sidebars_widgets', array());938 $sidebars_widgets = wp_get_sidebars_widgets(); 939 939 if ( isset($sidebars_widgets[$index]) && !empty($sidebars_widgets[$index]) ) 940 940 return true; … … 954 954 * @access private 955 955 * 956 * @param bool $update Optional, de fault is true. Whether to save upgrade of widget array list.957 * @return array Upgraded list of widgets to version 2 array format.958 */ 959 function wp_get_sidebars_widgets($ update= true) {956 * @param bool $update Optional, deprecated. 957 * @return array Upgraded list of widgets to version 3 array format when called from the admin. 958 */ 959 function wp_get_sidebars_widgets($deprecated = true) { 960 960 global $wp_registered_widgets, $wp_registered_sidebars, $_wp_sidebars_widgets; 961 961 962 962 // If loading from front page, consult $_wp_sidebars_widgets rather than options 963 963 // to see if wp_convert_widget_settings() has made manipulations in memory. 964 if ( is_admin() ) { 964 if ( !is_admin() ) { 965 if ( empty($_wp_sidebars_widgets) ) 966 $_wp_sidebars_widgets = get_option('sidebars_widgets', array()); 967 968 $sidebars_widgets = $_wp_sidebars_widgets; 969 } else { 965 970 $sidebars_widgets = get_option('sidebars_widgets', array()); 966 } else { 967 if ( empty($_wp_sidebars_widgets) ) 968 $sidebars_widgets = get_option('sidebars_widgets', array()); 969 else 970 $sidebars_widgets = &$_wp_sidebars_widgets; 971 } 972 $_sidebars_widgets = array(); 973 974 if ( !isset($sidebars_widgets['array_version']) ) 975 $sidebars_widgets['array_version'] = 1; 976 977 switch ( $sidebars_widgets['array_version'] ) { 978 case 1 : 979 foreach ( (array) $sidebars_widgets as $index => $sidebar ) 980 if ( is_array($sidebar) ) 981 foreach ( (array) $sidebar as $i => $name ) { 982 $id = strtolower($name); 983 if ( isset($wp_registered_widgets[$id]) ) { 984 $_sidebars_widgets[$index][$i] = $id; 985 continue; 971 $_sidebars_widgets = array(); 972 973 if ( isset($sidebars_widgets['wp_inactive_widgets']) ) 974 $sidebars_widgets['array_version'] = 3; 975 elseif ( !isset($sidebars_widgets['array_version']) ) 976 $sidebars_widgets['array_version'] = 1; 977 978 switch ( $sidebars_widgets['array_version'] ) { 979 case 1 : 980 foreach ( (array) $sidebars_widgets as $index => $sidebar ) 981 if ( is_array($sidebar) ) 982 foreach ( (array) $sidebar as $i => $name ) { 983 $id = strtolower($name); 984 if ( isset($wp_registered_widgets[$id]) ) { 985 $_sidebars_widgets[$index][$i] = $id; 986 continue; 987 } 988 $id = sanitize_title($name); 989 if ( isset($wp_registered_widgets[$id]) ) { 990 $_sidebars_widgets[$index][$i] = $id; 991 continue; 992 } 993 994 $found = false; 995 996 foreach ( $wp_registered_widgets as $widget_id => $widget ) { 997 if ( strtolower($widget['name']) == strtolower($name) ) { 998 $_sidebars_widgets[$index][$i] = $widget['id']; 999 $found = true; 1000 break; 1001 } elseif ( sanitize_title($widget['name']) == sanitize_title($name) ) { 1002 $_sidebars_widgets[$index][$i] = $widget['id']; 1003 $found = true; 1004 break; 1005 } 1006 } 1007 1008 if ( $found ) 1009 continue; 1010 1011 unset($_sidebars_widgets[$index][$i]); 986 1012 } 987 $id = sanitize_title($name); 988 if ( isset($wp_registered_widgets[$id]) ) { 989 $_sidebars_widgets[$index][$i] = $id; 990 continue; 991 } 992 993 $found = false; 994 995 foreach ( $wp_registered_widgets as $widget_id => $widget ) { 996 if ( strtolower($widget['name']) == strtolower($name) ) { 997 $_sidebars_widgets[$index][$i] = $widget['id']; 998 $found = true; 999 break; 1000 } elseif ( sanitize_title($widget['name']) == sanitize_title($name) ) { 1001 $_sidebars_widgets[$index][$i] = $widget['id']; 1002 $found = true; 1003 break; 1004 } 1005 } 1006 1007 if ( $found ) 1008 continue; 1009 1010 unset($_sidebars_widgets[$index][$i]); 1011 } 1012 $_sidebars_widgets['array_version'] = 2; 1013 $sidebars_widgets = $_sidebars_widgets; 1014 unset($_sidebars_widgets); 1015 1016 case 2 : 1017 $sidebars = array_keys( $wp_registered_sidebars ); 1018 if ( !empty( $sidebars ) ) { 1019 // Move the known-good ones first 1020 foreach ( (array) $sidebars as $id ) { 1021 if ( array_key_exists( $id, $sidebars_widgets ) ) { 1022 $_sidebars_widgets[$id] = $sidebars_widgets[$id]; 1023 unset($sidebars_widgets[$id], $sidebars[$id]); 1024 } 1025 } 1026 1027 // Assign to each unmatched registered sidebar the first available orphan 1028 unset( $sidebars_widgets[ 'array_version' ] ); 1029 while ( ( $sidebar = array_shift( $sidebars ) ) && $widgets = array_shift( $sidebars_widgets ) ) 1030 $_sidebars_widgets[ $sidebar ] = $widgets; 1031 1032 $_sidebars_widgets['array_version'] = 3; 1013 $_sidebars_widgets['array_version'] = 2; 1033 1014 $sidebars_widgets = $_sidebars_widgets; 1034 1015 unset($_sidebars_widgets); 1035 } 1036 1037 if ( $update && is_admin() ) 1038 update_option('sidebars_widgets', $sidebars_widgets); 1016 1017 case 2 : 1018 $sidebars = array_keys( $wp_registered_sidebars ); 1019 if ( !empty( $sidebars ) ) { 1020 // Move the known-good ones first 1021 foreach ( (array) $sidebars as $id ) { 1022 if ( array_key_exists( $id, $sidebars_widgets ) ) { 1023 $_sidebars_widgets[$id] = $sidebars_widgets[$id]; 1024 unset($sidebars_widgets[$id], $sidebars[$id]); 1025 } 1026 } 1027 1028 // move the rest to wp_inactive_widgets 1029 if ( !isset($_sidebars_widgets['wp_inactive_widgets']) ) 1030 $_sidebars_widgets['wp_inactive_widgets'] = array(); 1031 1032 if ( !empty($sidebars_widgets) ) { 1033 foreach ( $sidebars_widgets as $lost => $val ) { 1034 if ( is_array($val) ) 1035 $_sidebars_widgets['wp_inactive_widgets'] = array_merge( (array) $_sidebars_widgets['wp_inactive_widgets'], $val ); 1036 } 1037 } 1038 1039 $sidebars_widgets = $_sidebars_widgets; 1040 unset($_sidebars_widgets); 1041 } 1042 } 1039 1043 } 1040 1044 … … 1087 1091 */ 1088 1092 function wp_convert_widget_settings($base_name, $option_name, $settings) { 1089 global $_wp_sidebars_widgets;1090 1093 // This test may need expanding. 1091 $single = false;1094 $single = $changed = false; 1092 1095 if ( empty($settings) ) { 1093 1096 $single = true; … … 1111 1114 } else { 1112 1115 if ( empty($GLOBALS['_wp_sidebars_widgets']) ) 1113 $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets' );1116 $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array()); 1114 1117 $sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets']; 1115 1118 } … … 1120 1123 if ( $base_name == $name ) { 1121 1124 $sidebars_widgets[$index][$i] = "$name-2"; 1125 $changed = true; 1122 1126 break 2; 1123 1127 } … … 1126 1130 } 1127 1131 1128 if ( is_admin() )1132 if ( is_admin() && $changed ) 1129 1133 update_option('sidebars_widgets', $sidebars_widgets); 1130 1134 }
Note: See TracChangeset
for help on using the changeset viewer.