Changes from branches/2.8/wp-includes/widgets.php at r11690 to trunk/wp-includes/widgets.php at r11510
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/widgets.php
r11690 r11510 886 886 global $wp_registered_widgets; 887 887 888 $sidebars_widgets = wp_get_sidebars_widgets( );888 $sidebars_widgets = wp_get_sidebars_widgets(false); 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 = wp_get_sidebars_widgets();938 $sidebars_widgets = get_option( 'sidebars_widgets', array() ); 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 precated.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) {956 * @param bool $update Optional, default 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) { 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 $sidebars_widgets = get_option('sidebars_widgets', array()); 966 } else { 965 967 if ( empty($_wp_sidebars_widgets) ) 966 $_wp_sidebars_widgets = get_option('sidebars_widgets', array()); 967 968 $sidebars_widgets = $_wp_sidebars_widgets; 969 } else { 970 $sidebars_widgets = get_option('sidebars_widgets', array()); 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; 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; 986 } 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; 987 1004 } 988 $id = sanitize_title($name); 989 if ( isset($wp_registered_widgets[$id]) ) { 990 $_sidebars_widgets[$index][$i] = $id; 991 continue; 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]); 992 1024 } 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]);1012 1025 } 1013 $_sidebars_widgets['array_version'] = 2; 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; 1014 1033 $sidebars_widgets = $_sidebars_widgets; 1015 1034 unset($_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 } 1035 } 1036 1037 if ( $update && is_admin() ) 1038 update_option('sidebars_widgets', $sidebars_widgets); 1043 1039 } 1044 1040 … … 1091 1087 */ 1092 1088 function wp_convert_widget_settings($base_name, $option_name, $settings) { 1089 global $_wp_sidebars_widgets; 1093 1090 // This test may need expanding. 1094 $single = $changed =false;1091 $single = false; 1095 1092 if ( empty($settings) ) { 1096 1093 $single = true; … … 1114 1111 } else { 1115 1112 if ( empty($GLOBALS['_wp_sidebars_widgets']) ) 1116 $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets' , array());1113 $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets'); 1117 1114 $sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets']; 1118 1115 } … … 1123 1120 if ( $base_name == $name ) { 1124 1121 $sidebars_widgets[$index][$i] = "$name-2"; 1125 $changed = true;1126 1122 break 2; 1127 1123 } … … 1130 1126 } 1131 1127 1132 if ( is_admin() && $changed)1128 if ( is_admin() ) 1133 1129 update_option('sidebars_widgets', $sidebars_widgets); 1134 1130 }
Note: See TracChangeset
for help on using the changeset viewer.