Changeset 10912 for trunk/wp-includes/widgets.php
- Timestamp:
- 04/11/2009 02:37:24 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/widgets.php
r10822 r10912 50 50 * This function should check that $new_instance is set correctly. 51 51 * The newly calculated value of $instance should be returned. 52 * If "false" is returned, the instance won't be saved/updated. 52 53 * 53 54 * @param array $new_instance New settings for this instance as input by the user via form() 54 55 * @param array $old_instance Old settings for this instance 55 * @return array Settings to save 56 * @return array Settings to save or bool false to cancel saving 56 57 */ 57 58 function update($new_instance, $old_instance) { … … 192 193 $this_sidebar = array(); 193 194 194 foreach ( $this_sidebar as $_widget_id ) { 195 // Remove all widgets of this type from the sidebar. We'll add the 196 // new data in a second. This makes sure we don't get any duplicate 197 // data since widget ids aren't necessarily persistent across multiple 198 // updates 199 if ( $this->_get_display_callback() == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) { 200 $number = $wp_registered_widgets[$_widget_id]['params'][0]['number']; 201 if( !in_array( $this->id_base . '-' . $number, (array)$_POST['widget-id'] ) ) { 202 // the widget has been removed. 195 if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { 196 // Delete the settings for this instance of the widget 197 if ( isset($_POST['widget-id']) ) 198 $del_id = $_POST['widget-id']; 199 else 200 return; 201 202 if ( $this->_get_display_callback() == $wp_registered_widgets[$del_id]['callback'] && isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) { 203 $number = $wp_registered_widgets[$del_id]['params'][0]['number']; 204 205 if ( $this->id_base . '-' . $number == $del_id ) { 203 206 unset($all_instances[$number]); 204 207 } 205 208 } 206 } 207 208 foreach ( (array) $_POST['widget-' . $this->id_base] as $number => $new_instance ) { 209 $new_instance = stripslashes_deep($new_instance); 210 $this->_set($number); 211 212 if ( !isset($new_instance['submit']) ) 213 continue; 214 215 if ( isset($all_instances[$number]) ) 216 $instance = $this->update($new_instance, $all_instances[$number]); 217 else 218 $instance = $this->update($new_instance, array()); 219 220 if ( !empty($instance) ) 221 $all_instances[$number] = $instance; 209 } else { 210 foreach ( (array) $_POST['widget-' . $this->id_base] as $number => $new_instance ) { 211 $new_instance = stripslashes_deep($new_instance); 212 $this->_set($number); 213 214 if ( isset($all_instances[$number]) ) 215 $instance = $this->update($new_instance, $all_instances[$number]); 216 else 217 $instance = $this->update($new_instance, array()); 218 219 if ( false !== $instance ) 220 $all_instances[$number] = $instance; 221 } 222 222 } 223 223 … … 237 237 238 238 if ( -1 == $widget_args['number'] ) { 239 // We echo out a form where 'number' can be set later via JS240 $this->_set(' %i%');239 // We echo out a form where 'number' can be set later 240 $this->_set('__i__'); 241 241 $instance = array(); 242 242 } else { … … 246 246 247 247 $this->form($instance); 248 ?>249 <input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />250 <?php251 248 } 252 249 … … 254 251 function _register_one($number = -1) { 255 252 wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); 256 _register_widget_update_callback( $this->id, $this->name, $this->_get_update_callback(), $this->control_options, array( 'number' => $number) );253 _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) ); 257 254 _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) ); 258 255 } … … 580 577 581 578 $id = strtolower($id); 579 $update_id = preg_replace( '/-[0-9]+$/', '', $id ); 582 580 583 581 if ( empty($control_callback) ) { 584 582 unset($wp_registered_widget_controls[$id]); 585 unset($wp_registered_widget_updates[$ id]);583 unset($wp_registered_widget_updates[$update_id]); 586 584 return; 587 585 } … … 603 601 $widget = array_merge($widget, $options); 604 602 605 $wp_registered_widget_controls[$id] = $wp_registered_widget_updates[$id] = $widget; 606 } 607 608 function _register_widget_update_callback($id, $name, $update_callback, $options = array()) { 603 $wp_registered_widget_controls[$id] = $widget; 604 605 if ( isset($wp_registered_widget_updates[$update_id]) ) 606 return; 607 608 if ( isset($widget['params'][0]['number']) ) 609 $widget['params'][0]['number'] = -1; 610 611 unset($widget['width'], $widget['height'], $widget['name'], $widget['id']); 612 $wp_registered_widget_updates[$update_id] = $widget; 613 } 614 615 function _register_widget_update_callback($id_base, $update_callback, $options = array()) { 609 616 global $wp_registered_widget_updates; 610 617 611 $id = strtolower($id); 612 613 if ( empty($update_callback) ) { 614 unset($wp_registered_widget_updates[$id]); 618 if ( isset($wp_registered_widget_updates[$id_base]) ) { 619 if ( empty($update_callback) ) 620 unset($wp_registered_widget_updates[$id_base]); 615 621 return; 616 622 } 617 623 618 if ( isset($wp_registered_widget_updates[$id]) && !did_action( 'widgets_init' ) )619 return;620 621 $defaults = array('width' => 250, 'height' => 200 ); // height is never used622 $options = wp_parse_args($options, $defaults);623 $options['width'] = (int) $options['width'];624 $options['height'] = (int) $options['height'];625 626 624 $widget = array( 627 'name' => $name,628 'id' => $id,629 625 'callback' => $update_callback, 630 'params' => array_slice(func_get_args(), 4)626 'params' => array_slice(func_get_args(), 3) 631 627 ); 628 632 629 $widget = array_merge($widget, $options); 633 634 $wp_registered_widget_updates[$id] = $widget; 630 $wp_registered_widget_updates[$id_base] = $widget; 635 631 } 636 632 … … 648 644 return; 649 645 650 $defaults = array('width' => 250, 'height' => 200 ); // height is never used646 $defaults = array('width' => 250, 'height' => 200 ); 651 647 $options = wp_parse_args($options, $defaults); 652 648 $options['width'] = (int) $options['width'];
Note: See TracChangeset
for help on using the changeset viewer.