Changeset 10781
- Timestamp:
- 03/13/2009 10:27:38 PM (16 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/classes.php
r10764 r10781 1650 1650 $this->id_base = $id_base; 1651 1651 $this->name = $name; 1652 $this->option_name = 'w p_widget_' . $id_base;1652 $this->option_name = 'widget_' . $id_base; 1653 1653 $this->widget_options = wp_parse_args( $widget_options, array('classname' => $this->option_name) ); 1654 1654 $this->control_options = wp_parse_args( $control_options, array('id_base' => $this->id_base) ); 1655 1655 1656 //add_action( 'widgets_init', array( &$this, 'register' ) );1656 add_action( 'widgets_init', array( &$this, 'register' ) ); 1657 1657 } 1658 1658 … … 1672 1672 * Called during the 'widgets_init' action. */ 1673 1673 function register() { 1674 if ( ! $all_instances = get_option($this->option_name) ) 1675 $all_instances = array(); 1676 1677 $registered = false; 1678 foreach( array_keys($all_instances) as $number ) { 1679 // Old widgets can have null values for some reason 1680 if ( !isset($all_instances[$number]['_multiwidget']) ) 1681 continue; 1682 1683 $this->_set($number); 1684 $registered = true; 1685 $this->_register_one($number); 1686 } 1687 1688 // If there are none, we register the widget's existance with a 1689 // generic template 1690 if ( !$registered ) { 1674 $settings = $this->get_settings(); 1675 1676 if ( empty($settings) ) { 1677 // If there are none, we register the widget's existance with a 1678 // generic template 1691 1679 $this->_set(1); 1692 1680 $this->_register_one(); 1681 } elseif ( is_array($settings) ) { 1682 foreach ( array_keys($settings) as $number ) { 1683 if ( is_numeric($number) ) { 1684 $this->_set($number); 1685 $this->_register_one($number); 1686 } 1687 } 1693 1688 } 1694 1689 } … … 1718 1713 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); 1719 1714 $this->_set( $widget_args['number'] ); 1720 1721 // Data is stored as array: 1722 // array( number => data for that instance of the widget, ... ) 1723 $all_instances = get_option($this->option_name); 1724 if ( isset($all_instances[$this->number]) ) 1725 $this->widget($args, $all_instances[$this->number]); 1715 $settings = $this->get_settings(); 1716 1717 if ( array_key_exists( $this->number, $settings ) ) 1718 $this->widget($args, $settings[$this->number]); 1726 1719 } 1727 1720 … … 1735 1728 1736 1729 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); 1737 1738 // Data is stored as array: 1739 // array( number => data for that instance of the widget, ... ) 1740 $all_instances = get_option($this->option_name); 1741 if ( !is_array($all_instances) ) 1742 $all_instances = array(); 1730 $all_instances = $this->get_settings(); 1743 1731 1744 1732 // We need to update the data 1745 1733 if ( !$this->updated && !empty($_POST['sidebar']) ) { 1734 1746 1735 // Tells us what sidebar to put the data in 1747 1736 $sidebar = (string) $_POST['sidebar']; … … 1754 1743 1755 1744 foreach ( $this_sidebar as $_widget_id ) { 1756 // Remove all widgets of this type from the sidebar. 1757 // new data in a second. 1745 // Remove all widgets of this type from the sidebar. We'll add the 1746 // new data in a second. This makes sure we don't get any duplicate 1758 1747 // data since widget ids aren't necessarily persistent across multiple 1759 1748 // updates … … 1774 1763 $instance = $this->update($new_instance, array()); 1775 1764 1776 if ( !empty($instance) ) { 1777 $instance['_multiwidget'] = $number; 1765 if ( !empty($instance) ) 1778 1766 $all_instances[$number] = $instance; 1779 }1780 1767 } 1781 1768 1782 update_option($this->option_name,$all_instances);1783 $this->updated = true; // So that we don't go through this more than once1769 $this->save_settings($all_instances); 1770 $this->updated = true; 1784 1771 } 1785 1772 1786 1773 // Here we echo out the form 1787 1774 if ( -1 == $widget_args['number'] ) { 1788 // We echo out a template for a form which can be converted to a 1789 // specific form later via JS 1775 // We echo out a form where 'number' can be set later via JS 1790 1776 $this->_set('%i%'); 1791 1777 $instance = array(); … … 1794 1780 $instance = $all_instances[ $widget_args['number'] ]; 1795 1781 } 1782 1796 1783 $this->form($instance); 1797 1784 } … … 1802 1789 wp_register_widget_control( $this->id, $this->name, $this->_get_control_callback(), $this->control_options, array( 'number' => $number ) ); 1803 1790 } 1804 1791 1792 function save_settings($settings) { 1793 $settings['_multiwidget'] = 1; 1794 update_option( $this->option_name, $settings ); 1795 } 1796 1797 function get_settings() { 1798 $settings = get_option($this->option_name); 1799 1800 if ( !is_array($settings) ) 1801 return array(); 1802 1803 if ( !array_key_exists('_multiwidget', $settings) ) { 1804 // old format, conver if single widget 1805 $settings = wp_convert_widget_settings($this->id_base, $this->option_name, $settings); 1806 } 1807 1808 unset($settings['_multiwidget']); 1809 return $settings; 1810 } 1805 1811 } 1806 1812 -
trunk/wp-includes/widgets.php
r10774 r10781 656 656 657 657 return $defaults; 658 } 659 660 /** 661 * Convert the widget settings from single to multi-widget format. 662 * 663 * @since 2.8.0 664 * 665 * @return array 666 */ 667 function wp_convert_widget_settings($base_name, $option_name, $settings) { 668 // This test may need expanding. 669 $single = false; 670 foreach ( array_keys($settings) as $number ) { 671 if ( !is_numeric($number) ) { 672 $single = true; 673 break; 674 } 675 } 676 677 if ( $single ) { 678 $settings = array( 2 => $settings ); 679 680 $sidebars_widgets = get_option('sidebars_widgets'); 681 foreach ( (array) $sidebars_widgets as $index => $sidebar ) { 682 if ( is_array($sidebar) ) { 683 foreach ( $sidebar as $i => $name ) { 684 if ( $base_name == $name ) { 685 $sidebars_widgets[$index][$i] = "$name-2"; 686 break 2; 687 } 688 } 689 } 690 } 691 692 update_option('sidebars_widgets', $sidebars_widgets); 693 } 694 695 $settings['_multiwidget'] = 1; 696 update_option( $option_name, $settings ); 697 698 return $settings; 658 699 } 659 700 … … 768 809 return false; 769 810 770 return $new_instance; 811 $new_instance = (array) $new_instance; 812 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0); 813 foreach ( $instance as $field => $val ) { 814 if ( isset($new_instance[$field]) ) 815 $instance[$field] = 1; 816 } 817 818 return $instance; 771 819 } 772 820 … … 775 823 //Defaults 776 824 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false) ); 777 /*778 if ( isset($_POST['links-submit']) ) {779 $newoptions = array();780 $newoptions['description'] = isset($_POST['links-description']);781 $newoptions['name'] = isset($_POST['links-name']);782 $newoptions['rating'] = isset($_POST['links-rating']);783 $newoptions['images'] = isset($_POST['links-images']);784 785 if ( $instance != $newoptions ) {786 $instance = $newoptions;787 update_option('widget_links', $instance);788 }789 }790 */791 825 ?> 792 826 <p> … … 1976 2010 $widget_ops = array('description' => __( "Your blogroll" ) ); 1977 2011 $wp_widget_links = new WP_Widget_Links('links', __('Links'), $widget_ops); 1978 $wp_widget_links->register();2012 //$wp_widget_links->register(); 1979 2013 1980 2014 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
Note: See TracChangeset
for help on using the changeset viewer.