Make WordPress Core

Changeset 11510


Ignore:
Timestamp:
06/03/2009 11:33:17 AM (17 years ago)
Author:
azaozz
Message:

Improve widgets hooks, props Denis-de-Bernardy, fixes #10013

File:
1 edited

Legend:

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

    r11498 r11510  
    6565         */
    6666        function form($instance) {
    67                 echo '<p>' . __('There are no options for this widget.') . '</p>';
     67                echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>';
    6868                return 'noform';
    6969        }
    … …  
    169169                $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    170170                $this->_set( $widget_args['number'] );
    171                 $settings = $this->get_settings();
    172 
    173                 if ( array_key_exists( $this->number, $settings ) ) {
    174             $settings = $settings[$this->number];
     171                $instance = $this->get_settings();
     172
     173                if ( array_key_exists( $this->number, $instance ) ) {
     174                        $instance = $instance[$this->number];
    175175                        // filters the widget's settings, return false to stop displaying the widget
    176                         $settings = apply_filters('widget_display_callback', $settings, $this, $args);
    177             if ( false !== $settings )
    178                                 $this->widget($args, $settings);
    179         }
     176                        $instance = apply_filters('widget_display_callback', $instance, $this, $args);
     177                        if ( false !== $instance )
     178                                $this->widget($args, $instance);
     179                }
    180180        }
    181181
    … …  
    224224                                $this->_set($number);
    225225
    226                                 if ( isset($all_instances[$number]) )
    227                                         $instance = $this->update($new_instance, $all_instances[$number]);
    228                                 else
    229                                         $instance = $this->update($new_instance, array());
     226                                $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
     227
     228                                $instance = $this->update($new_instance, $old_instance);
    230229
    231230                                // 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);
     231                                $instance = apply_filters('widget_update_callback', $instance, $new_instance, $old_instance, $this);
    233232                                if ( false !== $instance )
    234233                                        $all_instances[$number] = $instance;
    … …  
    266265                if ( false !== $instance ) {
    267266                        $return = $this->form($instance);
    268                         if ( 'noform' !== $return )
    269                                 do_action_ref_array( 'in_widget_form', array(&$this) ); // add extra fields in the widget form
     267                        // add extra fields in the widget form - be sure to set $return to null if you add any
     268                        // if the widget has no form the text echoed from the default form method can be hidden using css
     269                        do_action_ref_array( 'in_widget_form', array(&$this, &$return, $instance) );
    270270                }
    271271                return $return;
Note: See TracChangeset for help on using the changeset viewer.