Make WordPress Core


Ignore:
Timestamp:
05/22/2009 12:08:51 PM (15 years ago)
Author:
azaozz
Message:

Fix saving and deleting of widgets settings for no-js and for some non-standard widgets, run the actions from the widgets screen when saving with ajax, see #9511

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/widgets.php

    r11380 r11427  
    192192
    193193        // We need to update the data
    194         if ( !$this->updated && !empty($_POST['sidebar']) ) {
    195 
    196             // Tells us what sidebar to put the data in
    197             $sidebar = (string) $_POST['sidebar'];
    198 
    199             $sidebars_widgets = wp_get_sidebars_widgets();
    200             if ( isset($sidebars_widgets[$sidebar]) )
    201                 $this_sidebar =& $sidebars_widgets[$sidebar];
     194        if ( $this->updated )
     195            return;
     196
     197        $sidebars_widgets = wp_get_sidebars_widgets();
     198
     199        if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
     200            // Delete the settings for this instance of the widget
     201            if ( isset($_POST['the-widget-id']) )
     202                $del_id = $_POST['the-widget-id'];
    202203            else
    203                 $this_sidebar = array();
    204 
    205             if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
    206                 // Delete the settings for this instance of the widget
    207                 if ( isset($_POST['widget-id']) )
    208                     $del_id = $_POST['widget-id'];
     204                return;
     205
     206            if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) {
     207                $number = $wp_registered_widgets[$del_id]['params'][0]['number'];
     208
     209                if ( $this->id_base . '-' . $number == $del_id )
     210                    unset($all_instances[$number]);
     211            }
     212        } else {
     213            if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) {
     214                $settings = $_POST['widget-' . $this->id_base];
     215            } elseif ( isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base ) {
     216                $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
     217                $settings = array( $num => array() );
     218            } else {
     219                return;
     220            }
     221
     222            foreach ( $settings as $number => $new_instance ) {
     223                $new_instance = stripslashes_deep($new_instance);
     224                $this->_set($number);
     225
     226                if ( isset($all_instances[$number]) )
     227                    $instance = $this->update($new_instance, $all_instances[$number]);
    209228                else
    210                     return;
    211 
    212                 if ( $this->_get_display_callback() == $wp_registered_widgets[$del_id]['callback'] && isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) {
    213                     $number = $wp_registered_widgets[$del_id]['params'][0]['number'];
    214 
    215                     if ( $this->id_base . '-' . $number == $del_id ) {
    216                         unset($all_instances[$number]);
    217                     }
    218                 }
    219             } else {
    220                 if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) {
    221                     $settings = $_POST['widget-' . $this->id_base];
    222                 } else {
    223                     $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
    224                     $settings = array( $num => array() );
    225                 }
    226 
    227                 foreach ( $settings as $number => $new_instance ) {
    228                     $new_instance = stripslashes_deep($new_instance);
    229                     $this->_set($number);
    230 
    231                     if ( isset($all_instances[$number]) )
    232                         $instance = $this->update($new_instance, $all_instances[$number]);
    233                     else
    234                         $instance = $this->update($new_instance, array());
    235 
    236                     // filters the widget's settings before saving, return false to cancel saving (keep the old settings if updating)
    237                     $instance = apply_filters('widget_update_callback', $instance, $new_instance, $this);
    238                     if ( false !== $instance )
    239                         $all_instances[$number] = $instance;
    240                 }
     229                    $instance = $this->update($new_instance, array());
     230
     231                // filters the widget's settings before saving, return false to cancel saving (keep the old settings if updating)
     232                $instance = apply_filters('widget_update_callback', $instance, $new_instance, $this);
     233                if ( false !== $instance )
     234                    $all_instances[$number] = $instance;
     235
     236                break; // run only once
    241237            }
    242 
    243             $this->save_settings($all_instances);
    244             $this->updated = true;
    245         }
     238        }
     239
     240        $this->save_settings($all_instances);
     241        $this->updated = true;
    246242    }
    247243
Note: See TracChangeset for help on using the changeset viewer.