wp_convert_widget_settings

Convert the widget settings from single to multi-widget format.

Description

(array) wp_convert_widget_settings( (string) $base_name, (string) $option_name, (array) $settings ); 

Returns (array)

Parameters (3)

0. $base_name (string)
The base name.
1. $option_name (string)
The option name.
2. $settings (array)
The settings.

Usage

  1. if ( !function_exists( 'wp_convert_widget_settings' ) ) { 
  2. require_once ABSPATH . WPINC . '/widgets.php'; 
  3.  
  4. // The base name. 
  5. $base_name = ''; 
  6.  
  7. // The option name. 
  8. $option_name = ''; 
  9.  
  10. // The settings. 
  11. $settings = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wp_convert_widget_settings($base_name, $option_name, $settings); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/widgets.php  
  1. function wp_convert_widget_settings($base_name, $option_name, $settings) { 
  2. // This test may need expanding. 
  3. $single = $changed = false; 
  4. if ( empty($settings) ) { 
  5. $single = true; 
  6. } else { 
  7. foreach ( array_keys($settings) as $number ) { 
  8. if ( 'number' == $number ) 
  9. continue; 
  10. if ( !is_numeric($number) ) { 
  11. $single = true; 
  12. break; 
  13.  
  14. if ( $single ) { 
  15. $settings = array( 2 => $settings ); 
  16.  
  17. // If loading from the front page, update sidebar in memory but don't save to options 
  18. if ( is_admin() ) { 
  19. $sidebars_widgets = get_option('sidebars_widgets'); 
  20. } else { 
  21. if ( empty($GLOBALS['_wp_sidebars_widgets']) ) 
  22. $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array()); 
  23. $sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets']; 
  24.  
  25. foreach ( (array) $sidebars_widgets as $index => $sidebar ) { 
  26. if ( is_array($sidebar) ) { 
  27. foreach ( $sidebar as $i => $name ) { 
  28. if ( $base_name == $name ) { 
  29. $sidebars_widgets[$index][$i] = "$name-2"; 
  30. $changed = true; 
  31. break 2; 
  32.  
  33. if ( is_admin() && $changed ) 
  34. update_option('sidebars_widgets', $sidebars_widgets); 
  35.  
  36. $settings['_multiwidget'] = 1; 
  37. if ( is_admin() ) 
  38. update_option( $option_name, $settings ); 
  39.  
  40. return $settings;