Widgets page, first run, see #9511
git-svn-id: http://svn.automattic.com/wordpress/trunk@10912 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -49,10 +49,11 @@ class WP_Widget {
|
||||
*
|
||||
* This function should check that $new_instance is set correctly.
|
||||
* The newly calculated value of $instance should be returned.
|
||||
* If "false" is returned, the instance won't be saved/updated.
|
||||
*
|
||||
* @param array $new_instance New settings for this instance as input by the user via form()
|
||||
* @param array $old_instance Old settings for this instance
|
||||
* @return array Settings to save
|
||||
* @return array Settings to save or bool false to cancel saving
|
||||
*/
|
||||
function update($new_instance, $old_instance) {
|
||||
return $new_instance;
|
||||
@@ -191,34 +192,33 @@ class WP_Widget {
|
||||
else
|
||||
$this_sidebar = array();
|
||||
|
||||
foreach ( $this_sidebar as $_widget_id ) {
|
||||
// Remove all widgets of this type from the sidebar. We'll add the
|
||||
// new data in a second. This makes sure we don't get any duplicate
|
||||
// data since widget ids aren't necessarily persistent across multiple
|
||||
// updates
|
||||
if ( $this->_get_display_callback() == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
|
||||
$number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
|
||||
if( !in_array( $this->id_base . '-' . $number, (array)$_POST['widget-id'] ) ) {
|
||||
// the widget has been removed.
|
||||
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
|
||||
// Delete the settings for this instance of the widget
|
||||
if ( isset($_POST['widget-id']) )
|
||||
$del_id = $_POST['widget-id'];
|
||||
else
|
||||
return;
|
||||
|
||||
if ( $this->_get_display_callback() == $wp_registered_widgets[$del_id]['callback'] && isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) {
|
||||
$number = $wp_registered_widgets[$del_id]['params'][0]['number'];
|
||||
|
||||
if ( $this->id_base . '-' . $number == $del_id ) {
|
||||
unset($all_instances[$number]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ( (array) $_POST['widget-' . $this->id_base] as $number => $new_instance ) {
|
||||
$new_instance = stripslashes_deep($new_instance);
|
||||
$this->_set($number);
|
||||
|
||||
foreach ( (array) $_POST['widget-' . $this->id_base] as $number => $new_instance ) {
|
||||
$new_instance = stripslashes_deep($new_instance);
|
||||
$this->_set($number);
|
||||
if ( isset($all_instances[$number]) )
|
||||
$instance = $this->update($new_instance, $all_instances[$number]);
|
||||
else
|
||||
$instance = $this->update($new_instance, array());
|
||||
|
||||
if ( !isset($new_instance['submit']) )
|
||||
continue;
|
||||
|
||||
if ( isset($all_instances[$number]) )
|
||||
$instance = $this->update($new_instance, $all_instances[$number]);
|
||||
else
|
||||
$instance = $this->update($new_instance, array());
|
||||
|
||||
if ( !empty($instance) )
|
||||
$all_instances[$number] = $instance;
|
||||
if ( false !== $instance )
|
||||
$all_instances[$number] = $instance;
|
||||
}
|
||||
}
|
||||
|
||||
$this->save_settings($all_instances);
|
||||
@@ -236,8 +236,8 @@ class WP_Widget {
|
||||
$all_instances = $this->get_settings();
|
||||
|
||||
if ( -1 == $widget_args['number'] ) {
|
||||
// We echo out a form where 'number' can be set later via JS
|
||||
$this->_set('%i%');
|
||||
// We echo out a form where 'number' can be set later
|
||||
$this->_set('__i__');
|
||||
$instance = array();
|
||||
} else {
|
||||
$this->_set($widget_args['number']);
|
||||
@@ -245,15 +245,12 @@ class WP_Widget {
|
||||
}
|
||||
|
||||
$this->form($instance);
|
||||
?>
|
||||
<input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
|
||||
<?php
|
||||
}
|
||||
|
||||
/** Helper function: Registers a single instance. */
|
||||
function _register_one($number = -1) {
|
||||
wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) );
|
||||
_register_widget_update_callback( $this->id, $this->name, $this->_get_update_callback(), $this->control_options, array( 'number' => $number ) );
|
||||
_register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) );
|
||||
_register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) );
|
||||
}
|
||||
|
||||
@@ -579,10 +576,11 @@ function wp_register_widget_control($id, $name, $control_callback, $options = ar
|
||||
global $wp_registered_widget_controls, $wp_registered_widget_updates;
|
||||
|
||||
$id = strtolower($id);
|
||||
$update_id = preg_replace( '/-[0-9]+$/', '', $id );
|
||||
|
||||
if ( empty($control_callback) ) {
|
||||
unset($wp_registered_widget_controls[$id]);
|
||||
unset($wp_registered_widget_updates[$id]);
|
||||
unset($wp_registered_widget_updates[$update_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -602,36 +600,34 @@ function wp_register_widget_control($id, $name, $control_callback, $options = ar
|
||||
);
|
||||
$widget = array_merge($widget, $options);
|
||||
|
||||
$wp_registered_widget_controls[$id] = $wp_registered_widget_updates[$id] = $widget;
|
||||
$wp_registered_widget_controls[$id] = $widget;
|
||||
|
||||
if ( isset($wp_registered_widget_updates[$update_id]) )
|
||||
return;
|
||||
|
||||
if ( isset($widget['params'][0]['number']) )
|
||||
$widget['params'][0]['number'] = -1;
|
||||
|
||||
unset($widget['width'], $widget['height'], $widget['name'], $widget['id']);
|
||||
$wp_registered_widget_updates[$update_id] = $widget;
|
||||
}
|
||||
|
||||
function _register_widget_update_callback($id, $name, $update_callback, $options = array()) {
|
||||
function _register_widget_update_callback($id_base, $update_callback, $options = array()) {
|
||||
global $wp_registered_widget_updates;
|
||||
|
||||
$id = strtolower($id);
|
||||
|
||||
if ( empty($update_callback) ) {
|
||||
unset($wp_registered_widget_updates[$id]);
|
||||
if ( isset($wp_registered_widget_updates[$id_base]) ) {
|
||||
if ( empty($update_callback) )
|
||||
unset($wp_registered_widget_updates[$id_base]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset($wp_registered_widget_updates[$id]) && !did_action( 'widgets_init' ) )
|
||||
return;
|
||||
|
||||
$defaults = array('width' => 250, 'height' => 200 ); // height is never used
|
||||
$options = wp_parse_args($options, $defaults);
|
||||
$options['width'] = (int) $options['width'];
|
||||
$options['height'] = (int) $options['height'];
|
||||
|
||||
$widget = array(
|
||||
'name' => $name,
|
||||
'id' => $id,
|
||||
'callback' => $update_callback,
|
||||
'params' => array_slice(func_get_args(), 4)
|
||||
'params' => array_slice(func_get_args(), 3)
|
||||
);
|
||||
$widget = array_merge($widget, $options);
|
||||
|
||||
$wp_registered_widget_updates[$id] = $widget;
|
||||
$widget = array_merge($widget, $options);
|
||||
$wp_registered_widget_updates[$id_base] = $widget;
|
||||
}
|
||||
|
||||
function _register_widget_form_callback($id, $name, $form_callback, $options = array()) {
|
||||
@@ -647,7 +643,7 @@ function _register_widget_form_callback($id, $name, $form_callback, $options = a
|
||||
if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) )
|
||||
return;
|
||||
|
||||
$defaults = array('width' => 250, 'height' => 200 ); // height is never used
|
||||
$defaults = array('width' => 250, 'height' => 200 );
|
||||
$options = wp_parse_args($options, $defaults);
|
||||
$options['width'] = (int) $options['width'];
|
||||
$options['height'] = (int) $options['height'];
|
||||
@@ -1072,4 +1068,4 @@ function register_widget_control($name, $control_callback, $width = '', $height
|
||||
*/
|
||||
function unregister_widget_control($id) {
|
||||
return wp_unregister_widget_control($id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user