Make WordPress Core

Ticket #9651: widgets.php.diff

File widgets.php.diff, 2.1 KB (added by ceenz, 15 years ago)
  • widgets.php

     
    164164                $this->_set( $widget_args['number'] );
    165165                $settings = $this->get_settings();
    166166
    167                 if ( array_key_exists( $this->number, $settings ) )
    168                         $this->widget($args, $settings[$this->number]);
     167                if ( array_key_exists( $this->number, $settings ) ) {
     168            $hide_widget = apply_filters('widget_display_test', $this); //Add hook to test if widget should be displayed. Sends the widget object as a variable. If the call returns ***false*** the widget will not be displayed.   
     169            if (!$hide_widget) $this->widget($args, $settings[$this->number]); //Test and display widget.
     170        }
    169171        }
    170172
    171173        /** Deal with changed settings.
     
    222224                                        else
    223225                                                $instance = $this->update($new_instance, array());
    224226
    225                                         if ( false !== $instance )
    226                                                 $all_instances[$number] = $instance;
     227                                        if ( false !== $instance ) {
     228                        $widget_options_compare = array($new_instance,$instance); //This array is used to compare the intended instance values (sent iva _POST) with the values overridden by the $this->update function.
     229                        $instance = apply_filters('default_widget_options_update',$widget_options_compare, $this);  //Callback to apply default and/or other options/instance values to be added to list of widget options/values to store in database. Should return widget options/values as array to be updated.
     230                        $all_instances[$number] = $instance;
     231                    }
    227232                                }
    228233                        }
    229234
     
    250255                        $instance = $all_instances[ $widget_args['number'] ];
    251256                }
    252257
    253                 return $this->form($instance);
     258                $this->form($instance);
     259       
     260        do_action('default_widget_options_display', $this); //Add action hook to display default widget information or options. Sends the widget object as a variable. Anything output by the called function will be displayed below the widget options set by the form function.
    254261        }
    255262
    256263        /** Helper function: Registers a single instance. */