目录
描述
Convert the widget settings from single to multi-widget format. See ticket #8441 for more information.
参数
$base_name
(string) (必填) The base slug for a widget type.
默认值: None
$option_name
(string) (必填) The name of the option where the widgets settings are saved.
默认值: None
$settings
(array) (必填) The array of settings for this type of widget.
默认值: None
返回值
(array)
The setting for the widget(s), updated to the multi-widget setting format introduced in 2.8
历史
添加于 版本: 2.8.0
源文件
wp_convert_widget_settings() 函数的代码位于 wp-includes/widgets.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ /** * Convert the widget settings from single to multi-widget format. * * @since 2.8.0 * * @global array $_wp_sidebars_widgets * * @param string $base_name * @param string $option_name * @param array $settings * @return array */ function wp_convert_widget_settings($base_name, $option_name, $settings) { // This test may need expanding. $single = $changed = false; if ( empty($settings) ) { $single = true; } else { foreach ( array_keys($settings) as $number ) { if ( 'number' == $number ) continue; if ( !is_numeric($number) ) { $single = true; break; } } } if ( $single ) { $settings = array( 2 => $settings ); // If loading from the front page, update sidebar in memory but don't save to options if ( is_admin() ) { $sidebars_widgets = get_option('sidebars_widgets'); } else { if ( empty($GLOBALS['_wp_sidebars_widgets']) ) $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array()); $sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets']; } foreach ( (array) $sidebars_widgets as $index => $sidebar ) { if ( is_array($sidebar) ) { foreach ( $sidebar as $i => $name ) { if ( $base_name == $name ) { $sidebars_widgets[$index][$i] = "$name-2"; $changed = true; break 2; } } } } if ( is_admin() && $changed ) update_option('sidebars_widgets', $sidebars_widgets); } $settings['_multiwidget'] = 1; if ( is_admin() ) update_option( $option_name, $settings ); return $settings; } |
- 原文:http://codex.wordpress.org/Function_Reference/wp_convert_widget_settings
- 翻译:黄聪@WordPress之魂